//vim: sw=4:ts=4:nu:nospell:fdc=4
/**
 * Simple Viewport Example
 *
 * @author Ing. Jozef Sakαlo�
 * @copyright (c) 2008, by Ing. Jozef Sakαlo�
 * @date 12. April 2008
 * @version $Id: simplevp.js 17 2008-04-24 14:57:16Z jozo $
 *
 * @license simplevp.js is licensed under the terms of the Open Source
 * LGPL 3.0 license. Commercial use is permitted to the extent that the
 * code/component(s) do NOT become part of another Open Source or Commercially
 * licensed development library or toolkit without explicit permission.
 *
 * License details: http://www.gnu.org/licenses/lgpl.html
 */

/*global Ext */



var workflow;
var carElements;
var viewport;
var figure;
var figures;
var selectedNode;
var selectedAddonNode;
var selectTextNode;
var selectTextParentNode;
var roleToEdit,addonsToEdit;
var qnrId;
var mctId;
var tamToEdit;
var title;
var tamTextNode;
var tamTextParentNode;
var activityId;
var htmlCode;

function setTamTextNode(tamTextNode)
{
	this.tamTextNode=tamTextNode;
	
}function getTamTextNode()
{
	return tamTextNode;
}

function getTamTextParentNode()
{
	return tamTextParentNode;
}
function setTamTextParentNode(tamTextParentNode)
{
	this.tamTextParentNode=tamTextParentNode;
}


function setTitle(title){
	this.title=title;
}
function getTitle(){
	return title;
}
function setTamToEdit(tamToEdit){
	this.tamToEdit=tamToEdit;
}
function getTamToEdit(){
	return tamToEdit;
}
function getSelectionNode()
{
	return selectedAddonNode;
}

function setSelectionNode(selectedAddonNode)
{
	this.selectedAddonNode=selectedAddonNode;
}
function setSelectTextNode(selectTextNode)
{
	this.selectTextNode=selectTextNode;
}
function getSelectTextNode()
{
	return selectTextNode;
}
function getSelectTextParentNode()
{
	return selectTextParentNode;
}

function setSelectTextParentNode(selectTextParentNode)
{
	this.selectTextParentNode=selectTextParentNode;
}
String.prototype.startsWith = function(prefix) {
    return this.indexOf(prefix) === 0;
}
function makeCheckBox(val){
		    return '<input name="check[]" value="+val+" type="checkbox">';
		}

Ext.require([
             'Ext.selection.CellModel',
             'Ext.window.MessageBox',
             'Ext.grid.*',
             'Ext.data.*',
             'Ext.util.*',
             'Ext.state.*',
             'Ext.form.*',
             'Ext.core.DomHelper',
             'Ext.ux.CheckColumn',
             'Ext.tip.*'
         ]);
   
Ext.onReady(function() {
	
	var deleteIcon = "/studentflow/ext-3.2.1/images/06-delete.png";
	var downloadIcon = "/studentflow/ext-3.2.1/images/Download.png";

	function renderDelIcon(del) {
	    return '<img src="' + deleteIcon + '"/>';
	}
	function renderDownloadIcon(val) {
	    return '<a href="fileUpload/view.action' + val + '">'+ '<img src="' + downloadIcon + '"></a>';
	}
	

	Ext.Ajax.request({
		url: 'configure/session.action',
		success: function(response,options) 
		{ 
			var tab  = tabPanel.getActiveTab();
			var responseText = response.responseText;
			var array=responseText.split(",");
			var addon = Ext.decode(response.responseText);
			var doc;
			if (window.DOMParser)
			  {
			  var parser=new DOMParser();
			  doc=parser.parseFromString(addon.graph,"text/xml");
			  }
			else // Internet Explorer
			  {
				doc=new ActiveXObject("Microsoft.XMLDOM");
				doc.async=false;
				doc.loadXML(addon.graph);
			  } 
			
			
			var pp = doc.documentElement.children;
			new deserializer_01.prototype.fromXML(pp, workflow);      
			var array2=array[3].split(":");
			tab.setTitle(array2[1]);
			Ext.getCmp("Export").enable(false);
		},
		params: { id: '' },
		failure: function(response,options) 
		{ 
			var west = Ext.getCmp('west-panel');
			west.getEl().mask();
			var east = Ext.getCmp('east-panel');
			east.getEl().mask();
			var center = Ext.getCmp('center-panel');
			center.getEl().mask();
		}
	});

	workflow  = new Workflow("center1");
	Ext.QuickTips.init();

	Ext.state.Manager.setProvider(Ext.create('Ext.state.CookieProvider'));

	//////////////////////////////////////////////////////////////////////////////////
	/*                         START  -  FORMS                                      */
	/*                                                                              */
	/*                                                                              */
	//////////////////////////////////////////////////////////////////////////////////


	var newUoLForm = new Ext.FormPanel({
		xtype:'form'
		,id:'uol-form'
		,defaultType:'textfield'
		,frame:true
		,method:'post'
		,url:'uol/createUoL.action'
		,defaults:{anchor:'95%'}
		,items:[{
			fieldLabel:'Title'
			,id:'title'
			,name:'title'
		},{
			xtype      : 'textareafield'
			,id        :'subject'
			,grow      : true
			,name      : 'subject'
			,fieldLabel: 'Subject'
			,anchor    : '100%'
		},{
			xtype      : 'textareafield'
			,id        :'description'
			,grow      : true
			,name      : 'description'
			,fieldLabel: 'Description'
			,anchor    : '100%'
			}]
		,buttonAlign:'right'
		,buttons:[
		          {text:'Cancel',
		        	  handler:function() {
		        		  newUoLWin.hide();
		        	  }},
		        	  {text:'Create' ,
		        		  handler:function() {
		        			  Ext.getCmp('uol-form').getForm().submit(
		        					  {params:{cmd:'submit'},
		        						  waitMsg: 'Creation of Learning Design...',
		        						  success: function(response) 
		        						  { 
		        							  var tab  = tabPanel.getActiveTab();
		        							  var title = response._fields.items[0].lastValue;
		        							  tab.setTitle(title);
		        							  newUoLWin.hide();
		        							  newUoLForm.getForm().reset();
		        							  var west = Ext.getCmp('west-panel');
		        							  west.getEl().unmask();
		        							  var east = Ext.getCmp('east-panel');
		        							  east.getEl().unmask();
		        							  var center = Ext.getCmp('center-panel');
		        							  center.getEl().unmask();
		        							  workflow.clear();
		        							  Ext.getCmp('addonsId').getStore().load();
		        							  Ext.getCmp('rolesTreeId').getStore().load();
		        							  Ext.getCmp("Export").enable(false);
		        						  }
		        					  ,
		        					  failure: function(form, action) {
		        						  Ext.Msg.alert('Error', 'Failed creating new Learning Design Or not loged in.'); 
		        						  newUoLWin.hide();
		        					  }
		        					  });
		        		  }
		        	  }	        	   
		        ]
	});

	var RoleAttributeForm = new Ext.FormPanel({
		xtype:'form'
		,id:'roleAttribute-form'
		,defaultType:'textfield'
		,frame:true
		,url: "role/saveAttributes.action"
		,defaults:{anchor:'95%'}
		,items:[{
			fieldLabel:'Title'
			,id:'text'
			,name:'text'
			,readOnly : true
		},{
			xtype: 'fieldset',
			title: 'Attributes',
			collapsible: true,
			defaultType: 'textfield',
			layout: 'anchor',
			defaults: {
				anchor: 'right',
				labelWidth: 300
			},
			items: [{
				xtype: 'radiofield',
				name: 'allowCreation',
				id: 'rb1',
				fieldLabel: 'Allow creation of multiple occurences during runtime',
				aling: 'right',
				boxLabel: 'Yes',
				inputValue: 'true'
			},{
				xtype: 'radiofield',
				name: 'allowCreation',
				id: 'rb2',
				fieldLabel: '',
				aling: 'right',
				labelSeparator: '',
				hideEmptyLabel: false,
				boxLabel: 'No',
				inputValue: 'false'
			},{
				xtype: 'radiofield',
				name: 'notAssignToOther',
				id: 'rb3',
				fieldLabel: 'Person assigned to this role may not be assigned to any other role',
				aling: 'right',
				boxLabel: 'Yes',
				inputValue: 'true'
			},{
				xtype: 'radiofield',
				name: 'notAssignToOther',
				id: 'rb4',
				fieldLabel: '',
				aling: 'right',
				labelSeparator: '',
				hideEmptyLabel: false,
				boxLabel: 'No',
				inputValue: 'false'
			},{
				fieldLabel:'Minimun number of Persons'
				,id:'minPersons'
				,name:'minPersons'
				,value: 'minPersons'
			},{
				fieldLabel:'Maximun number of Persons'
				,id:'maxPersons'
				,name:'maxPersons'
				,value: 'maxPersons'
			}]
			},{
				xtype: 'htmleditor',
				name: 'information',
				id: 'information',
				fieldLabel: 'Addition Information',
				height: 200,
				anchor: '100%'
			}]
				,buttonAlign:'right'
				,buttons:[
				          {text:'Cancel',
				        	  handler:function() {
				        		  RoleAttributeForm.getForm().reset();
				        		  newRoleAttributeWin.hide();
				       	  }},
				       	  {text:'Update' ,
				       		  handler:function() {
				       			  Ext.getCmp('roleAttribute-form').getForm().submit(
				      					  {
				       						  waitMsg: 'Updating Role Attributes...',
				       						  success: function(response) 
				       						  { 
				       							  RoleAttributeForm.getForm().reset();
				       							  newRoleAttributeWin.hide();
				       						  },
					        				  failure: function(form, action) {
					        					  Ext.Msg.alert('Error', 'Failed editing role'); 
					        					  RoleAttributeForm.getForm().reset();
					        					  newRoleAttributeWin.hide();
					        				  }
					        			 });
					        		  }
					        	  }	        	   
					        	  ]
				});

	var AddonTextWorkAttributeForm = new Ext.FormPanel({
		xtype:'form'
		,id:'addonTextWorkAttribute-form'
		,defaultType:'textfield'
		,frame:true
		,url: "addons/saveAddonTextWorkAttributes.action"
		,defaults:{anchor:'95%'}
		,items:[{
			fieldLabel:'Title'
			,id:'text'
			,name:'text'
			,readOnly : true
		},{
			xtype: 'fieldset',
			title: 'Attributes',
			collapsible: true,
			defaultType: 'textfield',
			layout: 'anchor',
			defaults: {
				anchor: 'right',
				labelWidth: 300
			},
			items: [{
				xtype: 'radiofield',
				name: 'effort',
				id: 'tw1',
				fieldLabel: 'How will the test-writing take place?',
				aling: 'right',
				boxLabel: 'Individual Effort',
				inputValue: '0'
			},{
				xtype: 'radiofield',
				name: 'effort',
				id: 'tw2',
				fieldLabel: '',
				aling: 'right',
				labelSeparator: '',
				hideEmptyLabel: false,
				boxLabel: 'Group Effort',
				inputValue: '1'
			},{
				fieldLabel:'Minimun number of Persons'
				,id:'minPersons'
				,name:'minPersons'
			},{
				fieldLabel:'Maximun number of Persons'
				,id:'maxPersons'
				,name:'maxPersons'
			}]
			}]
				,buttonAlign:'right'
				,buttons:[
				          {text:'Cancel',
				        	  handler:function() {
				        		  newTextWorkWin.hide();
				       	  }},
				       	  {text:'Update' ,
				       		  handler:function() {
				       			  Ext.getCmp('addonTextWorkAttribute-form').getForm().submit(
				      					  {
				       						  waitMsg: 'Updating Text Work Attributes...',
				       						  success: function(response) 
				       						  { 
				       							newTextWorkWin.hide();
				       						  },
					        				  failure: function(form, action) {
					        					  Ext.Msg.alert('Error', 'Failed editing Text Work'); 
					        					  newTextWorkWin.hide();
					        				  }
					        			 });
					        		  }
					        	  }	        	   
					        	  ]
				});
	
	
	var AddonUploadingFilesAttributeForm = new Ext.FormPanel({
		xtype:'form'
			,id:'addonUploadingFilesAttribute-form'
			,defaultType:'textfield'
			,frame:true
			,url: "addons/saveAddonUploadingFilesAttributes.action"
			,defaults:{anchor:'95%'}
			,items:[{
				fieldLabel:'Title'
				,id:'text'
				,name:'text'
				,readOnly : true
			},{
				xtype: 'fieldset',
				title: 'Attributes',
				collapsible: true,
				defaultType: 'textfield',
				layout: 'anchor',
				defaults: {
					anchor: 'right',
					labelWidth: 300
				},
				items: [{
					xtype: 'radiofield',
					name: 'effort',
					id: 'uf1',
					fieldLabel: 'How will the test-writing take place?',
					aling: 'right',
					boxLabel: 'Individual Effort',
					inputValue: '0'
				},{
					xtype: 'radiofield',
					name: 'effort',
					id: 'uf2',
					fieldLabel: '',
					aling: 'right',
					labelSeparator: '',
					hideEmptyLabel: false,
					boxLabel: 'Group Effort',
					inputValue: '1'
				},{
					fieldLabel:'Minimun number of Persons'
					,id:'minPersons'
					,name:'minPersons'
				},{
					fieldLabel:'Maximun number of Persons'
					,id:'maxPersons'
					,name:'maxPersons'
				}]
				}]
					,buttonAlign:'right'
					,buttons:[
					          {text:'Cancel',
					        	  handler:function() {
					        		  newUploadingFilesWin.hide();
					       	  }},
					       	  {text:'Update' ,
					       		  handler:function() {
					       			  Ext.getCmp('addonUploadingFilesAttribute-form').getForm().submit(
					      					  {
					       						  waitMsg: 'Updating Uploading Files Attributes...',
					       						  success: function(response) 
					       						  { 
					       							newUploadingFilesWin.hide();
					       						  },
						        				  failure: function(form, action) {
						        					  Ext.Msg.alert('Error', 'Failed editing Uploading Files Attribute'); 
						        					  newUploadingFilesWin.hide();
						        				  }
						        			 });
						        		  }
						        	  }	        	   
						        	  ]
					});
	
	
	
	var AddonQnRAttributeForm = new Ext.FormPanel({
		xtype:'form'
			,id:'addonQnRAttribute-form'
			,defaultType:'textfield'
			,frame:true
			,url: "addons/saveAddonQnRAttributes.action"
			,defaults:{anchor:'95%'}
			,items:[{
				fieldLabel:'Title'
				,id:'text'
				,name:'text'
				,readOnly : true
			},{
				xtype: 'fieldset',
				title: 'Attributes',
				collapsible: true,
				defaultType: 'textfield',
				layout: 'anchor',
				defaults: {
					anchor: 'right',
					labelWidth: 300
				},
				items: [{
					xtype: 'radiofield',
					name: 'effort',
					id: 'qnr1',
					fieldLabel: 'How will the test-writing take place',
					aling: 'right',
					boxLabel: 'Individual Effort',
					inputValue: '0'
				},{
					xtype: 'radiofield',
					name: 'effort',
					id: 'qnr2',
					fieldLabel: '',
					aling: 'right',
					labelSeparator: '',
					hideEmptyLabel: false,
					boxLabel: 'Group Effort',
					inputValue: '1'
				},
				{
					fieldLabel:'Minimun number of Persons'
					,id:'minPersons'
					,name:'minPersons'
				},{
					fieldLabel:'Maximun number of Persons'
					,id:'maxPersons'
					,name:'maxPersons'
				}]
				}]
					,buttonAlign:'right'
					,buttons:[
					          {text:'Cancel',
					        	  handler:function() {
					        		  newQnRWin.hide();
					       	  }},{text:'Show/Edit Questions',
					       		  id :'showEditQuestions',
					       		  disabled : true,
					       		  hidden : true,
					        	  handler:function() {
					        		  newQuestionsWin.show();
					       	  }},
					       	  {text:'Update' ,
					       		  handler:function() {
					       			  Ext.getCmp('addonQnRAttribute-form').getForm().submit(
					      					  {
					       						  waitMsg: 'Updating Question and Answers Attributes...',
					       						  success: function(response) 
					       						  { 
					       							qnrId = this.result.questionsAndAnswers.id;
					       							
					       							var questions = response.getValues().questions;
					       							if(questions == "0"){
					       								newQuestionsWin.show();
					       								newQnRWin.hide();
					       							}else{
					       								newQnRWin.hide();	
					       							}
					       						  },
						        				  failure: function(form, action) {
						        					  Ext.Msg.alert('Error', 'Failed editing Question and Answers Attribute'); 
						        					  newQnRWin.hide();
						        				  }
						        			 });
						        		  }
						        	  }	        	   
						        	  ]
					});
	
	var g = Ext.create('Ext.grid.PropertyGrid', {
		title: 'Property Grid',
		closable: true,
		source: {
			"Name": "",
			"Min Number of Persons": 0,
			"Max Number of Persons": 0,
			"productionQuality": false,
			"created": Ext.Date.parse('10/15/2006', 'd/m/Y'),
			"tested": false,
			"version": 0.01,
			"borderWidth": 1,
			"boss": true,
			"ActorId": 0
		}
	});
	
	var AddonMcTAttributeForm = new Ext.FormPanel({
		xtype:'form'
			,id:'addonMctAttribute-form'
			,defaultType:'textfield'
			,frame:true
			,url: "addons/saveAddonMcTAttributes.action"
			,defaults: {
					anchor: 'right',
					labelWidth: 250
				}
			,items:[{
				fieldLabel:'Title'
				,id:'text'
				,name:'text'
				,readOnly : true
			},

				{
					fieldLabel:'Number of Questions to be defined'
					,id:'nuQuestions'
					,name:'nuQuestions'
				},{
					fieldLabel:'Number of possible answers per question'
					,id:'nuPossibleAnswers'
					,name:'nuPossibleAnswers'
				}]
				
					,buttonAlign:'right'
					,buttons:[
					          {text:'Cancel',
					        	  handler:function() {
					        		  newMcTWin.hide();
					       	  }},
					       	  {text:'Update' ,
					       		  handler:function() {
					       			  Ext.getCmp('addonMctAttribute-form').getForm().submit(
					      					  {
					       						  waitMsg: 'Updating Multiple-Choice Test Attributes...',
					       						  success: function(response) 
					       						  { 					       							
					       							var questions = response.getValues().questions;
					       							mctId = this.result.multipleChoice.id;
					       							if(questions == "0"){
					       								newMcTQuestionsWin.show();
					       								newMcTWin.hide();
					       							}else{
					       								newMcTWin.hide();	
					       							}
					       						  },
						        				  failure: function(form, action) {
						        					  Ext.Msg.alert('Error', 'Failed editing Multiple-Choice Test Attribute'); 
						        					  newMcTWin.hide();
						        				  }
						        			 });
						        		  }
						        	  }	        	   
						        	  ]
					});
	
	    var counter = 1; //label number counter

	var AddonQuestionsAttributeForm = new Ext.FormPanel({
		xtype:'form'
			,id:'addonQuestionsAttribute-form'
			,defaultType:'textfield'
			,frame:true
			,autoScroll:true
			,url: "addons/saveAddonQuestionsAttributes.action"
			,defaults:{anchor:'95%'}
			,items:[{
				fieldLabel:'Question-1'
					,id:'text'
					,name:'text'
				}]
					,buttonAlign:'right'
					,buttons:[{text:'Cancel',
			        	  handler:function() {
			        		  var lastQuestion = AddonQuestionsAttributeForm.items.length;
			                	var k = lastQuestion;
								for(k = lastQuestion; k>0; k--){
									AddonQuestionsAttributeForm.remove(AddonQuestionsAttributeForm.items.items[k]);
									AddonQuestionsAttributeForm.doLayout();
								}
								newQuestionsWin.hide();
			        	  }},{
		                text: 'Add New Question',
		                handler: function () {
		                	counter++;
		                	var tf = Ext.create('Ext.form.field.Text', {
		                        name: 'text',
		                        fieldLabel: 'Question-'+counter
		                    });
		                	AddonQuestionsAttributeForm.add(tf);
		                	AddonQuestionsAttributeForm.doLayout();
		                }
		            },{
		                text: 'Remove Last Question',
		                handler: function () {
		                	var lastQuestion = AddonQuestionsAttributeForm.items.length;
		                	if(lastQuestion>1){
		                		counter--;
			                	AddonQuestionsAttributeForm.remove(AddonQuestionsAttributeForm.items.items[lastQuestion-1]);
			                	AddonQuestionsAttributeForm.doLayout();
		                	}else{
		                		Ext.Msg.alert('False', 'You must at least enter one Question'); 
		                	}
		                }
		            },{ 
		    			text:'Save',
		    			formBind: true,	 
		    			handler:function() {
		    				Ext.getCmp('addonQuestionsAttribute-form').getForm().submit(
		    						{params:{
		    							node: getSelectTextNode()
		    								},
		    							waitMsg: 'Creation of Questions...',
		    							success: function(response) 
		    							{ 
		    								var lastQuestion = AddonQuestionsAttributeForm.items.length;
		    								var k = lastQuestion;
		    								for(k = lastQuestion; k>0; k--){
		    									AddonQuestionsAttributeForm.remove(AddonQuestionsAttributeForm.items.items[k]);
		    									AddonQuestionsAttributeForm.doLayout();
		    								}
		    								newQuestionsWin.hide();
		    								Ext.getCmp('addonsId').getStore().load();

		    							}
		    						,
		    						failure: function(form, action) {
		    							Ext.Msg.alert('Error', 'Failed creating Questions'); 
		    							newQuestionsWin.hide();
		    						}
		    						});
		    			}
		    		}
					          ]
					});
	
	
	var counter2=1;
	var AddonMcTQuestionsAttributeForm = new Ext.FormPanel({
		xtype:'form'
			,id:'addonMcTQuestionsAttribute-form'
			,defaultType:'textfield'
			,frame:true
			,autoScroll:true
			,url: "addons/saveAddonMcTQuestionsAttributes.action"
			,defaults:{anchor:'95%'}
			,items:[{
					fieldLabel:'Question-1'
						,id:'text' 
						,name: 'question'
					},{
					fieldLabel:'Answers-1'
						,id:'answer'
						,name:'answer'
					}]
					,buttonAlign:'right'
					,buttons:[{ 
						text:'Cancel',
						handler:function(){ 
							var lastQuestion = AddonMcTQuestionsAttributeForm.items.length;
		                	var k = lastQuestion;
							for(k = lastQuestion; k>1; k--){
								AddonMcTQuestionsAttributeForm.remove(AddonMcTQuestionsAttributeForm.items.items[k]);
		                		AddonMcTQuestionsAttributeForm.doLayout();
							}
							newMcTQuestionsWin.hide();
						 
						}
					},{
		                text: 'Add New Question',
		                handler: function () {
		                	counter2++;
		                	var tf = Ext.create('Ext.form.field.Text', {
		                        name: 'question',
		                        fieldLabel: 'Question-'
		                    });
		                	var ans = Ext.create('Ext.form.field.Text', {
		                        name: 'answer',
		                        fieldLabel: 'Comma Separated Answers-'
		                    });
		                	AddonMcTQuestionsAttributeForm.add(tf);
		                	AddonMcTQuestionsAttributeForm.add(ans);
		                	AddonMcTQuestionsAttributeForm.doLayout();
		                }
		            },{
		                text: 'Remove Last Question',
		                handler: function () {
		                	var lastQuestion = AddonMcTQuestionsAttributeForm.items.length;
		                	if(lastQuestion>2){
		                		counter2--;
		                		AddonMcTQuestionsAttributeForm.remove(AddonMcTQuestionsAttributeForm.items.items[lastQuestion-1]);
		                		AddonMcTQuestionsAttributeForm.remove(AddonMcTQuestionsAttributeForm.items.items[lastQuestion-2]);
		                		AddonMcTQuestionsAttributeForm.doLayout();
		                	}else{
		                		Ext.Msg.alert('False', 'You must at least enter one Multiple-Choice Test Question'); 
		                	}
		                }
		            },{ 
		    			text:'Save',
		    			formBind: true,	 
		    			handler:function() {
		    				Ext.getCmp('addonMcTQuestionsAttribute-form').getForm().submit(
		    						{params:{
		    							node: getSelectTextNode()
		    								},
		    							waitMsg: 'Creation of Multiple-Choice Test Questions...',
		    							success: function(response) 
		    							{ 
		    								var lastQuestion = AddonMcTQuestionsAttributeForm.items.length;
		    			                	var k = lastQuestion;
		    								for(k = lastQuestion; k>1; k--){
		    									AddonMcTQuestionsAttributeForm.remove(AddonMcTQuestionsAttributeForm.items.items[k]);
		    			                		AddonMcTQuestionsAttributeForm.doLayout();
		    								}
		    								newMcTQuestionsWin.hide();
		    								Ext.getCmp('addonsId').getStore().load();

		    							}
		    						,
		    						failure: function(form, action) {
		    							Ext.Msg.alert('Error', 'Failed creating Multiple-Choice Tests Questions'); 
		    							AddonMcTQuestionsAttributeForm.getForm().reset();
		    							newMcTQuestionsWin.hide();
		    						}
		    						});
		    			}
		    		}
					          ]
					});
	
//////////////////////////////////Addons starups creation forms START//////////////////////////////////////////////
	
	var newTextAdd = new Ext.FormPanel({ 
		labelWidth:80,
		url:'addons/text.action', 
		id:'textadd-form',
		frame:true, 
		defaultType:'textfield',
		items:[{ 
			fieldLabel:'Title', 
			name:'title', 
			allowBlank:false 
		}],
		buttons:[{ 
			text:'Cancel',
			handler:function(){ 
				newTextAddWin.hide();
			} 
		},{ 
			text:'Save',
			formBind: true,	 
			handler:function() {
				Ext.getCmp('textadd-form').getForm().submit(
						{params:{cmd:'submit'},
							waitMsg: 'Creation of Text Addon...',
							success: function(response) 
							{ 
								newTextAdd.getForm().reset();
								newTextAddWin.hide();
								Ext.getCmp('addonsId').getStore().load();

							}
						,
						failure: function(form, action) {
							Ext.Msg.alert('Error', 'Failed creating new Text Addon Or Text Addon title already exists'); 
							newTextAddWin.hide();
						}
						});
			}
		}] 
	});
	
	var newUFAdd = new Ext.FormPanel({ 
		labelWidth:80,
		url:'addons/uf.action', 
		id:'UF-form',
		frame:true, 
		defaultType:'textfield',

		items:[{ 
			fieldLabel:'Title', 
			name:'title', 
			allowBlank:false 
		}],
		buttons:[{ 
			text:'Cancel',
			handler:function(){ 
				newUFAddWin.hide();
			} 
		},{ 
			text:'Save',
			formBind: true,	 
			handler:function() {
				Ext.getCmp('UF-form').getForm().submit(
						{params:{cmd:'submit'},
							waitMsg: 'Creation of Uploading Files Addon...',
							success: function(response) 
							{ 
								newUFAdd.getForm().reset();
								newUFAddWin.hide();
								Ext.getCmp('addonsId').getStore().load();

							}
						,
						failure: function(form, action) {
							Ext.Msg.alert('Error', 'Failed creating new Uploading Files Addon Or Uploading Files Addon title already exists'); 
							newUFAddWin.hide();
						}
						});
			}
		}] 
	});	
	var newQnRAdd = new Ext.FormPanel({ 
		labelWidth:80,
		url:'addons/qnr.action', 
		id:'QnR-form',
		frame:true, 
		defaultType:'textfield',

		items:[{ 
			fieldLabel:'Title', 
			name:'title', 
			allowBlank:false 
		}],
		buttons:[{ 
			text:'Cancel',
			handler:function(){ 
				newQnRAddWin.hide();
			} 
		},{ 
			text:'Save',
			formBind: true,	 
			handler:function() {
				Ext.getCmp('QnR-form').getForm().submit(
						{params:{cmd:'submit'},
							waitMsg: 'Creation of Question and Answer Addon...',
							success: function(response) 
							{ 
								newQnRAdd.getForm().reset();
								newQnRAddWin.hide();
								Ext.getCmp('addonsId').getStore().load();

							}
						,
						failure: function(form, action) {
							Ext.Msg.alert('Error', 'Failed creating new Question and Answers Addon Or Question and Answers Addon title already exists'); 
							newQnRAddWin.hide();
						}
						});
			}
		}] 
	});
	
	var newMtCAdd = new Ext.FormPanel({ 
		labelWidth:80,
		url:'addons/mtc.action', 
		id:'MtC-form',
		frame:true, 
		defaultType:'textfield',

		items:[{ 
			fieldLabel:'Title', 
			name:'title', 
			allowBlank:false 
		}],
		buttons:[{ 
			text:'Cancel',
			handler:function(){ 
				newMtCAddWin.hide();
			} 
		},{ 
			text:'Save',
			formBind: true,	 
			handler:function() {
				Ext.getCmp('MtC-form').getForm().submit(
						{params:{cmd:'submit'},
							waitMsg: 'Creation of Multiple Choice Addon...',
							success: function(response) 
							{ 
								newMtCAdd.getForm().reset();
								newMtCAddWin.hide();
								Ext.getCmp('addonsId').getStore().load();

							}
						,
						failure: function(form, action) {
							Ext.Msg.alert('Error', 'Failed creating new Multiple Choice Addon Or Multiple Choice Addon title already exists'); 
							newMtCAddWin.hide();
						}
						});
			}
		}] 
	});
	
	var newTextAddWin = new Ext.Window({
		layout:'fit',
		title: 'Create new TextWork Addon',
		width:280,
		height:80,
		closable: false,
		resizable: false,
		plain: true,
		border: false,
		items: [newTextAdd]
	});
	var newUFAddWin = new Ext.Window({
		layout:'fit',
		title: 'Create new Uploading File',
		width:280,
		height:80,
		closable: false,
		resizable: false,
		plain: true,
		border: false,
		items: [newUFAdd]
	});
	var newQnRAddWin = new Ext.Window({
		layout:'fit',
		title: 'Create new Question And Answers',
		width:280,
		height:80,
		closable: false,
		resizable: false,
		plain: true,
		border: false,
		items: [newQnRAdd]
	});
	var newMtCAddWin = new Ext.Window({
		layout:'fit',
		title: 'Create new Multiple Choice',
		width:280,
		height:80,
		closable: false,
		resizable: false,
		plain: true,
		border: false,
		items: [newMtCAdd]
	});
	
	var newQuestionsWin = new Ext.Window({
		layout:'fit',
		title: 'Create/Edit Questions for Question and Answers Addon',
		width:530,
		height:330,
		closable: false,
		resizable: false,
		plain: true,
		border: false,
		items: [AddonQuestionsAttributeForm]
	});
	
	
	var newMcTQuestionsWin = new Ext.Window({
		layout:'fit',
		title: 'Create/Edit Questions for Multiple-Choice Tests Addon',
		width:530,
		height:330,
		closable: false,
		resizable: false,
		plain: true,
		border: false,
		items: [AddonMcTQuestionsAttributeForm]
	});
	
	var menuAddon = new Ext.menu.Menu({
		id: 'menuAddon', items: [
		                     { text: 'New Add-on ' ,
		                    	 iconCls:'add',
		                    	 handler:function(index, event, addonsTree, node) {
		                    		
		                    		 if( getSelectionNode() == 1){
		                    			 newTextAdd.getForm().reset();
		                    			 newTextAddWin.show();
		                    		 } else if(getSelectionNode() == 2){
		                    			 newUFAdd.getForm().reset();
		                    			 newUFAddWin.show();
		                    		 }else if(getSelectionNode() == 3){
		                    			 newQnRAdd.getForm().reset();
		                    			 newQnRAddWin.show();
		                    		 }else {
		                    			 newMtCAdd.getForm().reset();
		                    			 newMtCAddWin.show();
		                    		 }
		                    	 }}	 
		                     ]
	});
	
	var menuAddonDefineQuestions = new Ext.menu.Menu({
		id: 'menuAddonDefineQuestions', items: [
		                     { text: 'Add/Edit Questions Now' ,
		                    	 iconCls:'questions',
		                    	 handler:function(index, event, addonsTree, node) {
		                    		
		                    		 if( getSelectTextParentNode().indexOf("Add-ons/Multiple-choice Test")===0){
		                    			 AddonMcTQuestionsAttributeForm.getForm().reset();
		                    			 Ext.Ajax.request({
		         							url: 'addons/getMtcQuestionAttributes.action',
		         							method: 'GET',
		         							params: {
		         								node: getSelectTextNode()
		         							},
		         							success: function(response, callOptions) 
		         							{ 
		         								
		         								var addon = Ext.decode(response.responseText);
		         								if((addon.as.length>0 && addon.qs.length>0)){
		         									
		         									var i=1;
		         									for (i=1;i<addon.as.length;i++)
		         									{
		         										var tf = Ext.create('Ext.form.field.Text', {
		         					                        name: 'question',
		         					                        fieldLabel: 'Question-'+i
		         					                    });
		         					                	var ans = Ext.create('Ext.form.field.Text', {
		         					                        name: 'answer',
		         					                        fieldLabel: 'Comma Separated Answers-'+i
		         					                    });
		         					                	AddonMcTQuestionsAttributeForm.add(tf);
		         					                	AddonMcTQuestionsAttributeForm.add(ans);
		         					                	AddonMcTQuestionsAttributeForm.doLayout();
		         									}
		         									var addonMcTQuestionsAttribute = AddonMcTQuestionsAttributeForm.getForm();
		         									var k=0;
		         									var j = 0;
		         									var t = 0;
		         									for (j=0;j<addon.as.length;j++)
		         									{
		         											addonMcTQuestionsAttribute.getFields().items[k].setValue(addon.qs[j]);
		         											k=k+2;
		         									}
		         									var k=1;
		         									for (t=0;t<addon.as.length;t++)
		         									{
		         											addonMcTQuestionsAttribute.getFields().items[k].setValue(addon.as[t]);
		         											k=k+2;
		         									}
		         									console.log("asdads");
		         								}
		                    			 newMcTQuestionsWin.show();
		         							}
		                    			 });
		                    		 } else if(getSelectTextParentNode().indexOf("Add-ons/Question and Answers")===0){
		                    			 Ext.Ajax.request({
			         							url: 'addons/getQuestionnAnswersAttributes.action',
			         							method: 'GET',
			         							params: {
			         								node: getSelectTextNode()
			         							},
			         							success: function(response, callOptions) 
			         							{ 
			         								
			         								var addon = Ext.decode(response.responseText);
			         								if((addon.qs.length>0)){
			         									
			         									var i=1;
			         									for (i=1;i<addon.qs.length;i++)
			         									{
			         										var tf = Ext.create('Ext.form.field.Text', {
			         					                        name: 'text',
			         					                        fieldLabel: 'Question-'+i
			         					                    });
			         					                	
			         					                	AddonQuestionsAttributeForm.add(tf);
			         					                	AddonQuestionsAttributeForm.doLayout();
			         									}
			         									var addonQuestionsAttributeForm = AddonQuestionsAttributeForm.getForm();
			         									var k=0;
			         									var j = 0;
			         									for(k=0;k<addon.qs.length;k++){
			         										addonQuestionsAttributeForm.getFields().items[k].setValue(addon.qs[k]);			         										
			         									}

			         								}
			         								newQuestionsWin.show();
			         							}
			                    			 });
		                    			 
		                    		 }
		                    	 }}	 
		                     ]
	});
	
	var storeUoL = Ext.create('Ext.data.Store', {
		id:'storeUoL',
		autoLoad: true,
		fields:['id','title','subject'],
		pageSize: 10, // items per page
		proxy: {
			type: 'ajax',
			url: 'uol/view.action',  // url that will load data with respect to User and limit params
			reader: {
				type: 'json',
				root: 'items',
				totalProperty: 'total'
			}
		}
	});

	var gridUoL = Ext.create('Ext.grid.Panel', {
		title: 'Learning Design',
		store: storeUoL,
		columns: [
		          {header: 'Id',  dataIndex: 'id', flex:1},
		          {header: 'Title', dataIndex: 'title', flex:2},//
		          {header: 'Subject', dataIndex: 'subject', flex:3}
		          ],
		          width: 400,
		          height: 175,
		          dockedItems: [{
		        	  xtype: 'pagingtoolbar',
		        	  store: storeUoL, 
		        	  dock: 'bottom',
		        	  displayInfo: true
		          }]
	}); 
	
	var storeFilesLADescription = Ext.create('Ext.data.Store', {
		id:'storeFilesLADescription',
		autoLoad: true,
		fields:['id','name','size'],
		pageSize: 10, // items per page
		proxy: {
			type: 'ajax',
			url: 'fileUpload/viewLADescription.action',
			reader: {
				type: 'json',
				root: 'items',
				totalProperty: 'total'
			}
		}
	});
	
	var storeFilesSADescription = Ext.create('Ext.data.Store', {
		id:'storeFilesSADescription',
		autoLoad: true,
		fields:['id','name','size'],
		pageSize: 10, // items per page
		proxy: {
			type: 'ajax',
			url: 'fileUpload/viewSADescription.action',
			reader: {
				type: 'json',
				root: 'items',
				totalProperty: 'total'
			}
		}
	});
	
    Ext.define('Recipient', {
        extend: 'Ext.data.Model',
        fields: [{name: 'roleName', type: 'string'},
                 {name: 'recipient', type: 'bool'}
        ]
    });

	
	
	var toolBarfilesGridLADescription = Ext.create('Ext.toolbar.Toolbar', {
		region: 'north',
		height: 32, // give north and south regions a height
		items: [{
			text   : "Delete",
			handler: function() {
				 var gridrecord = gridFilesLADescription.getSelectionModel().lastSelected.data.id;   
					Ext.Ajax.request({
						url: 'fileUpload/delLADescription.action',
						params:{del:gridrecord},
						success: function(response,options) 
						{ 
							storeFilesLADescription.load();
						},
						failure: function(response,options) 
						{ 
							
						}
					});
			}
			},{
				text   : "Download",
				handler: function() {
					 var gridrecord = gridFilesLADescription.getSelectionModel().lastSelected.data.id;   
					 window.open('fileUpload/downloadLADescription.action?download='+gridrecord);
				}
				}]
	});
	
	var toolBarfilesGridSADescription = Ext.create('Ext.toolbar.Toolbar', {
		region: 'north',
		height: 32, // give north and south regions a height
		items: [{
			text   : "Delete",
			handler: function() {
				 var gridrecord = gridFilesSADescription.getSelectionModel().lastSelected.data.id;   
					Ext.Ajax.request({
						url: 'fileUpload/delSADescription.action',
						params:{del:gridrecord},
						success: function(response,options) 
						{ 
							storeFilesSADescription.load();
						},
						failure: function(response,options) 
						{ 
							
						}
					});
			}
			},{
				text   : "Download",
				handler: function() {
					 var gridrecord = gridFilesSADescription.getSelectionModel().lastSelected.data.id;   
					 window.open('fileUpload/downloadSADescription.action?download='+gridrecord);
				}
				}]
	});

	var gridFilesLADescription = Ext.create('Ext.grid.Panel', {
		title: 'Learning Activiry Resources',
		store: storeFilesLADescription,
		columns: [
		          {header: 'Id',  dataIndex: 'id', flex:1},
		          {header: 'FileName', dataIndex: 'name', flex:2},//
		          {header: 'Size', dataIndex: 'size', flex:3}
		          ],
		          tbar:[toolBarfilesGridLADescription],
		          width: 400,
		          height: 175,
		          dockedItems: [{
		        	  xtype: 'pagingtoolbar',
		        	  store: storeFilesLADescription,   // same store GridPanel is using
		        	  dock: 'bottom',
		        	  displayInfo: true
		          }]
	}); 
	
	var gridFilesSADescription = Ext.create('Ext.grid.Panel', {
		title: 'Support Activiry Resources',
		store: storeFilesSADescription,
		columns: [
		          {header: 'Id',  dataIndex: 'id', flex:1},
		          {header: 'FileName', dataIndex: 'name', flex:2},//
		          {header: 'Size', dataIndex: 'size', flex:3}
		          ],
		          tbar:[toolBarfilesGridSADescription],
		          width: 400,
		          height: 175,
		          dockedItems: [{
		        	  xtype: 'pagingtoolbar',
		        	  store: storeFilesSADescription,   // same store GridPanel is using
		        	  dock: 'bottom',
		        	  displayInfo: true
		          }]
	}); 
	 
	var viewFilesLADescriptionWin = new Ext.Window({
		title: 'View Description Resources/Files',
		applyTo:'hello-win',
		width:410,
		height:238,
		closeAction:'hide',
		plain: true,
		items: gridFilesLADescription 
	});
	
	var viewFilesSADescriptionWin = new Ext.Window({
		title: 'View Description Resources/Files',
		applyTo:'hello-win',
		width:410,
		height:238,
		closeAction:'hide',
		plain: true,
		items: gridFilesSADescription 
	});
	
	var storeFilesLAObjective = Ext.create('Ext.data.Store', {
		id:'storeFilesLAObjective',
		autoLoad: true,
		fields:['id','name','size'],
		pageSize: 10, // items per page
		proxy: {
			type: 'ajax',
			url: 'fileUpload/viewLAObjective.action',
			reader: {
				type: 'json',
				root: 'items',
				totalProperty: 'total'
			}
		}
	});
	
	var toolBarfilesGridLAObjective = Ext.create('Ext.toolbar.Toolbar', {
		region: 'north',
		height: 32, // give north and south regions a height
		items: [{
			text   : "Delete",
			handler: function() {
				 var gridrecord = gridFilesLAObjective.getSelectionModel().lastSelected.data.id;   
					Ext.Ajax.request({
						url: 'fileUpload/delLAObjective.action',
						params:{del:gridrecord},
						success: function(response,options) 
						{ 
							storeFilesLAObjective.load();
						},
						failure: function(response,options) 
						{ 
							
						}
					});
			}
			},{
				text   : "Download",
				handler: function() {
					 var gridrecord = gridFilesLAObjective.getSelectionModel().lastSelected.data.id;   
					 window.open('fileUpload/downloadLAObjective.action?download='+gridrecord);
				}
				}]
	});
	var gridFilesLAObjective = Ext.create('Ext.grid.Panel', {
		title: 'Learning Activiry Resources',
		store: storeFilesLAObjective,
		columns: [
		          {header: 'Id',  dataIndex: 'id', flex:1},
		          {header: 'FileName', dataIndex: 'name', flex:2},//
		          {header: 'Size', dataIndex: 'size', flex:3}
		          ],
		          tbar:[toolBarfilesGridLAObjective],
		          width: 400,
		          height: 175,
		          dockedItems: [{
		        	  xtype: 'pagingtoolbar',
		        	  store: storeFilesLAObjective,   // same store GridPanel is using
		        	  dock: 'bottom',
		        	  displayInfo: true
		          }]
	}); 
	 
	var viewFilesLAObjectiveWin = new Ext.Window({
		title: 'View Objective Resources/Files',
		applyTo:'hello-win',
		width:410,
		height:238,
		closeAction:'hide',
		plain: true,
		items: gridFilesLAObjective 
	});
	
	var storeFilesLAPrerequisites = Ext.create('Ext.data.Store', {
		id:'storeFilesLAPrerequisite',
		autoLoad: true,
		fields:['id','name','size'],
		pageSize: 10, // items per page
		proxy: {
			type: 'ajax',
			url: 'fileUpload/viewLAPrerequisite.action',
			reader: {
				type: 'json',
				root: 'items',
				totalProperty: 'total'
			}
		}
	});
	
	var toolBarfilesGridLAPrerequisite = Ext.create('Ext.toolbar.Toolbar', {
		region: 'north',
		height: 32, // give north and south regions a height
		items: [{
			text   : "Delete",
			handler: function() {
				 var gridrecord = gridFilesLAPrerequisite.getSelectionModel().lastSelected.data.id;   
					Ext.Ajax.request({
						url: 'fileUpload/delLAPrerequisite.action',
						params:{del:gridrecord},
						success: function(response,options) 
						{ 
							storeFilesLAPrerequisites.load();
						},
						failure: function(response,options) 
						{ 
							
						}
					});
			}
			},{
				text   : "Download",
				handler: function() {
					 var gridrecord = gridFilesLAPrerequisite.getSelectionModel().lastSelected.data.id;   
					 window.open('fileUpload/downloadLAPrerequisite.action?download='+gridrecord);
				}
				}]
	});
	var gridFilesLAPrerequisite = Ext.create('Ext.grid.Panel', {
		title: 'Learning Activiry Resources',
		store: storeFilesLAPrerequisites,
		columns: [
		          {header: 'Id',  dataIndex: 'id', flex:1},
		          {header: 'FileName', dataIndex: 'name', flex:2},//
		          {header: 'Size', dataIndex: 'size', flex:3}
		          ],
		          tbar:[toolBarfilesGridLAPrerequisite],
		          width: 400,
		          height: 175,
		          dockedItems: [{
		        	  xtype: 'pagingtoolbar',
		        	  store: storeFilesLAPrerequisites,   // same store GridPanel is using
		        	  dock: 'bottom',
		        	  displayInfo: true
		          }]
	}); 
	 
	var viewFilesLAPrerequisitesWin = new Ext.Window({
		title: 'View Prerequisite Resources/Files',
		applyTo:'hello-win',
		width:410,
		height:238,
		closeAction:'hide',
		plain: true,
		items: gridFilesLAPrerequisite 
	});
//////////////////////////////////Addons starups creation forms END//////////////////////////////////////////////
	var newStaffRole = new Ext.FormPanel({ 
		labelWidth:80,
		url:'role/staff.action', 
		id:'StaffRole-form',
		frame:true, 
		defaultType:'textfield',

		items:[{ 
			fieldLabel:'Role', 
			name:'role', 
			allowBlank:false 
		}],
		buttons:[{ 
			text:'Cancel',
			handler:function(){ 
				newStaffRoleWin.hide();
			} 
		},{ 
			text:'Save',
			formBind: true,	 
			handler:function() {
				Ext.getCmp('StaffRole-form').getForm().submit(
						{params:{cmd:'submit'},
							waitMsg: 'Creation of Staff Role...',
							success: function(response) 
							{ 
								newStaffRole.getForm().reset();
								newStaffRoleWin.hide();
								Ext.getCmp('rolesTreeId').getStore().load();

							}
						,
						failure: function(form, action) {
							Ext.Msg.alert('Error', 'Failed creating new Staff Role Or Role title already exists'); 
							newStaffRoleWin.hide();
						}
						});
			}
		}] 
	});

	var newLearnerRole = new Ext.FormPanel({ 
		labelWidth:80,
		url:'role/learner.action', 
		id: 'LearnerRole-form',
		frame:true, 
		defaultType:'textfield',
		items:[{ 
			fieldLabel:'Role', 
			name:'role', 
			allowBlank:false 
		}],
		buttons:[{ 
			text:'Cancel',
			handler:function(){ 
				newLearnerRoleWin.hide();
			} 
		},{ 
			text:'Save',
			formBind: true,	 
			handler:function() {
				Ext.getCmp('LearnerRole-form').getForm().submit(
						{params:{cmd:'submit'},
							waitMsg: 'Creation of new Learner Role...',
							success: function(response, rolesTree) 
							{ 
								newLearnerRole.getForm().reset();
								newLearnerRoleWin.hide();
								Ext.getCmp('rolesTreeId').getStore().load();

							}
						,
						failure: function(form, action) {
							Ext.Msg.alert('Error', 'Failed creating new Learner Role Or Role title already exists'); 
							newLearnerRoleWin.hide();
						}
						});
			}
		}] 
	});
	

	
	var newLearningObject = new Ext.FormPanel({ 
		labelWidth:80,
		url:'tam/lo.action', 
		id: 'LearningObject-form',
		frame:true, 
		defaultType:'textfield',
		items:[{ 
			fieldLabel:'Learning Object', 
			name:'lo', 
			allowBlank:false 
		}],
		buttons:[{ 
			text:'Cancel',
			handler:function(){ 
				newLearningObjectWin.hide();
			} 
		},{ 
			text:'Save',
			formBind: true,	 
			handler:function() {
				Ext.getCmp('LearningObject-form').getForm().submit(
						{params:{cmd:'submit'},
							waitMsg: 'Creation of new Learning Object...',
							success: function(response) 
							{ 
								newLearningObject.getForm().reset();
								newLearningObjectWin.hide();
								Ext.getCmp('toolsAndMaterialsId').getStore().load();

							}
						,
						failure: function(form, action) {
							Ext.Msg.alert('Error', 'Failed creating new Learning Object Or Learning Object title already exists'); 
							newLearningObjectWin.hide();
						}
						});
			}
		}] 
	});
	
	var newForumService = new Ext.FormPanel({ 
		labelWidth:80,
		url:'tam/fs.action', 
		id: 'ForumService-form',
		frame:true, 
		defaultType:'textfield',
		items:[{ 
			fieldLabel:'Forum Service', 
			name:'fs', 
			allowBlank:false 
		}],
		buttons:[{ 
			text:'Cancel',
			handler:function(){ 
				newForumServiceWin.hide();
			} 
		},{ 
			text:'Save',
			formBind: true,	 
			handler:function() {
				Ext.getCmp('ForumService-form').getForm().submit(
						{params:{cmd:'submit'},
							waitMsg: 'Creation of new Forum Service...',
							success: function(response) 
							{ 
								newForumService.getForm().reset();
								newForumServiceWin.hide();
								Ext.getCmp('toolsAndMaterialsId').getStore().load();

							}
						,
						failure: function(form, action) {
							Ext.Msg.alert('Error', 'Failed creating new Forum Service Or Forum Service title already exists'); 
							newForumServiceWin.hide();
						}
						});
			}
		}] 
	});
	
	
	var newAnnouncementService = new Ext.FormPanel({ 
		labelWidth:80,
		url:'tam/as.action', 
		id: 'AnnouncementService-form',
		frame:true, 
		defaultType:'textfield',
		items:[{ 
			fieldLabel:'Announcement Service', 
			name:'as', 
			allowBlank:false 
		}],
		buttons:[{ 
			text:'Cancel',
			handler:function(){ 
				newAnnouncementServiceWin.hide();
			} 
		},{ 
			text:'Save',
			formBind: true,	 
			handler:function() {
				Ext.getCmp('AnnouncementService-form').getForm().submit(
						{params:{cmd:'submit'},
							waitMsg: 'Creation of new Announcement Service...',
							success: function(response) 
							{ 
								newAnnouncementService.getForm().reset();
								newAnnouncementServiceWin.hide();
								Ext.getCmp('toolsAndMaterialsId').getStore().load();

							}
						,
						failure: function(form, action) {
							Ext.Msg.alert('Error', 'Failed creating new Announcement Service Or Announcement Service title already exists'); 
							newAnnouncementServiceWin.hide();
						}
						});
			}
		}] 
	});
	
	
	var newChatService = new Ext.FormPanel({ 
		labelWidth:80,
		url:'tam/cs.action', 
		id: 'ChatService-form',
		frame:true, 
		defaultType:'textfield',
		items:[{ 
			fieldLabel:'Chat Service', 
			name:'cs', 
			allowBlank:false 
		}],
		buttons:[{ 
			text:'Cancel',
			handler:function(){ 
				newChatServiceWin.hide();
			} 
		},{ 
			text:'Save',
			formBind: true,	 
			handler:function() {
				Ext.getCmp('ChatService-form').getForm().submit(
						{params:{cmd:'submit'},
							waitMsg: 'Creation of new Chat Service...',
							success: function(response) 
							{ 
								newChatService.getForm().reset();
								newChatServiceWin.hide();
								Ext.getCmp('toolsAndMaterialsId').getStore().load();

							}
						,
						failure: function(form, action) {
							Ext.Msg.alert('Error', 'Failed creating new Chat Service Or Chat Service title already exists'); 
							newChatServiceWin.hide();
						}
						});
			}
		}] 
	});
	
	
	var newSentMail = new Ext.FormPanel({ 
		labelWidth:80,
		url:'tam/sm.action', 
		id: 'SentMail-form',
		frame:true, 
		defaultType:'textfield',
		items:[{ 
			fieldLabel:'Sent Mail', 
			name:'sm', 
			allowBlank:false 
		}],
		buttons:[{ 
			text:'Cancel',
			handler:function(){ 
				newSentMailWin.hide();
			} 
		},{ 
			text:'Save',
			formBind: true,	 
			handler:function() {
				Ext.getCmp('SentMail-form').getForm().submit(
						{params:{cmd:'submit'},
							waitMsg: 'Creation of new Sent Mail...',
							success: function(response) 
							{ 
								newSentMail.getForm().reset();
								newSentMailWin.hide();
								Ext.getCmp('toolsAndMaterialsId').getStore().load();

							}
						,
						failure: function(form, action) {
							Ext.Msg.alert('Error', 'Failed creating new Sent Mail Or Sent Mail title already exists'); 
							newSentMailWin.hide();
						}
						});
			}
		}] 
	});
	
    var learningActivityAddResourceLADescriptionForm = new Ext.FormPanel({
    	id:'learningActivityAddResourceFormLADescription',
        fileUpload: true,
        width: 500,
        frame: true,
        url: 'fileUpload/uploadLADescription.action',
        closable:false,
        title: 'File Upload Form',
        autoHeight: true,
        bodyStyle: 'padding: 10px 10px 0 10px;',
        labelWidth: 50,
        defaults: {
            anchor: '95%',
            allowBlank: false,
            msgTarget: 'side'
        },
        items: [{
            xtype: 'fileuploadfield',
            id: 'file',
            emptyText: 'Select a File to import',
            fieldLabel: 'File',
            name: 'file',
            buttonCfg: {
                text: '',
                iconCls: 'upload-icon'
            }
        }],
        buttons: [{
            text: 'Upload',
     		  handler:function() {
     			
       			  Ext.getCmp('learningActivityAddResourceFormLADescription').getForm().submit(
      					  {
      						  params:{activityId:activityId}
	        		 });
       			  		setActivityId(activityId);
       			  		learningActivityAddResourceLADescriptionWin.hide();
	        		  }
        },{
            text: 'Reset',
            handler: function(){
            	learningActivityAddResourceLADescriptionForm.getForm().reset();
            }
        },{
            text: 'Close',
            handler: function(){
            	learningActivityAddResourceLADescriptionForm.getForm().reset();
            	learningActivityAddResourceLADescriptionWin.hide();
            }
        }]
    });
    
    var supportActivityAddResourceSADescriptionForm = new Ext.FormPanel({
    	id:'supportActivityAddResourceFormSADescription',
        fileUpload: true,
        width: 500,
        frame: true,
        url: 'fileUpload/uploadSADescription.action',
        closable:false,
        title: 'File Upload Form',
        autoHeight: true,
        bodyStyle: 'padding: 10px 10px 0 10px;',
        labelWidth: 50,
        defaults: {
            anchor: '95%',
            allowBlank: false,
            msgTarget: 'side'
        },
        items: [{
            xtype: 'fileuploadfield',
            id: 'file',
            emptyText: 'Select a File to import',
            fieldLabel: 'File',
            name: 'file',
            buttonCfg: {
                text: '',
                iconCls: 'upload-icon'
            }
        }],
        buttons: [{
            text: 'Upload',
     		  handler:function() {
     			
       			  Ext.getCmp('supportActivityAddResourceFormSADescription').getForm().submit(
      					  {
      						  params:{activityId:activityId}
	        		 });
       			  		setActivityId(activityId);
       			  		supportActivityAddResourceSADescriptionWin.hide();
	        		  }
        },{
            text: 'Reset',
            handler: function(){
            	supportActivityAddResourceSADescriptionForm.getForm().reset();
            }
        },{
            text: 'Close',
            handler: function(){
            	supportActivityAddResourceSADescriptionForm.getForm().reset();
            	supportActivityAddResourceSADescriptionWin.hide();
            }
        }]
    });
    
    var learningActivityAddResourceLAObjectiveForm = new Ext.FormPanel({
    	id:'learningActivityAddResourceFormLAObjective',
        fileUpload: true,
        width: 500,
        frame: true,
        url: 'fileUpload/uploadLAObjective.action',
        closable:false,
        title: 'File Upload Form',
        autoHeight: true,
        bodyStyle: 'padding: 10px 10px 0 10px;',
        labelWidth: 50,
        defaults: {
            anchor: '95%',
            allowBlank: false,
            msgTarget: 'side'
        },
        items: [{
            xtype: 'fileuploadfield',
            id: 'file',
            emptyText: 'Select a File to import',
            fieldLabel: 'File',
            name: 'file',
            buttonCfg: {
                text: '',
                iconCls: 'upload-icon'
            }
        }],
        buttons: [{
            text: 'Upload',
     		  handler:function() {
     			
       			  Ext.getCmp('learningActivityAddResourceFormLAObjective').getForm().submit(
      					  {
      						  params:{activityId:activityId}
	        			 });
       			  		setActivityId(activityId);
       			  		learningActivityAddResourceLAObjectiveWin.hide();
	        		  }
        },{
            text: 'Reset',
            handler: function(){
            	learningActivityAddResourceLAObjectiveForm.getForm().reset();
            }
        },{
            text: 'Close',
            handler: function(){
            	learningActivityAddResourceLAObjectiveForm.getForm().reset();
            	learningActivityAddResourceLAObjectiveWin.hide();
            }
        }]
    });
    
    
    var importLDForm = new Ext.FormPanel({
    	id:'importLDForm',
       // fileUpload: true,
        width: 500,
        frame: true,
        url: 'fileUpload/importLD.action',
        closable:false,
        title: 'Import Learning Design',
        autoHeight: true,
        bodyStyle: 'padding: 10px 10px 0 10px;',
        labelWidth: 50,
        defaults: {
            anchor: '95%',
            allowBlank: false,
            msgTarget: 'side'
        },
        items: [{
            xtype: 'fileuploadfield',
            id: 'file',
            emptyText: 'Select a File to import',
            fieldLabel: 'File',
            name: 'file',
            buttonCfg: {
                text: '',
                iconCls: 'upload-icon'
            }
        }],
        buttons: [{
            text: 'Upload',
     		  handler:function() {
     			
       			  Ext.getCmp('importLDForm').getForm().submit(
      					  {
      						  params:{},
      						success:function(form, action){ 
      							if(action.response.responseText.indexOf("true") > -1){
      								Ext.Msg.alert('Success', 'Your Learning Design successfully import to ASK-LDT 2.0');
      								
      								window.location.reload();
      							}else{
      								 Ext.Msg.alert('Error', 'Problem occur during import LD'); 
      							}
                            	
                            },
                             
	        			 });
       			  		
       			  		importLDWin.hide();
	        		  }
        },{
            text: 'Reset',
            handler: function(){
            	importLDForm.getForm().reset();
            }
        },{
            text: 'Close',
            handler: function(){
            	importLDForm.getForm().reset();
            	importLDWin.hide();
            }
        }]
    });
    
    
    var learningActivityAddResourceLAPrerequisitesForm = new Ext.FormPanel({
    	id:'learningActivityAddResourceFormLAPrerequisites',
        fileUpload: true,
        width: 500,
        frame: true,
        url: 'fileUpload/uploadLAPrerequisite.action',
        closable:false,
        title: 'File Upload Form',
        autoHeight: true,
        bodyStyle: 'padding: 10px 10px 0 10px;',
        labelWidth: 50,
        defaults: {
            anchor: '95%',
            allowBlank: false,
            msgTarget: 'side'
        },
        items: [{
            xtype: 'fileuploadfield',
            id: 'file',
            emptyText: 'Select a File to import',
            fieldLabel: 'File',
            name: 'file',
            buttonCfg: {
                text: '',
                iconCls: 'upload-icon'
            }
        }],
        buttons: [{
            text: 'Upload',
     		  handler:function() {
     			
       			  Ext.getCmp('learningActivityAddResourceFormLAPrerequisites').getForm().submit(
      					  {
      						  params:{activityId:activityId}
	        			 });
       			  		setActivityId(activityId);
       			  		learningActivityAddResourceLAPrerequisitesWin.hide();
	        		  }
        },{
            text: 'Reset',
            handler: function(){
            	learningActivityAddResourceLAPrerequisitesForm.getForm().reset();
            }
        },{
            text: 'Close',
            handler: function(){
            	learningActivityAddResourceLAPrerequisitesForm.getForm().reset();
            	learningActivityAddResourceLAPrerequisitesWin.hide();
            }
        }]
    });
    
    Ext.define('LAAddon', {
        extend: 'Ext.data.Model',
        fields: [{name: 'id', type: 'string'},
                 {name: 'type', type: 'string'},
                 {name: 'text', type: 'string'},
                 {name: 'enable', type: 'bool'}
        ]
    });
    
    Ext.define('LATam', {
        extend: 'Ext.data.Model',
        fields: [{name: 'id', type: 'string'},
                 {name: 'type', type: 'string'},
                 {name: 'text', type: 'string'},
                 {name: 'enable', type: 'bool'}
        ]
    });
    
    var cellEditing = Ext.create('Ext.grid.plugin.CellEditing', {
        clicksToEdit: 1
    });
    
	var laAddonStore = Ext.create('Ext.data.Store', {
		id:'laAddonStore',
		autoLoad: true,
	    model: 'LAAddon',
		pageSize: 100, // items per page
		autoSave: true,
		proxy: {
			type: 'ajax',
			url:'addons/laGrid.action',  // url that will load data with respect to User and limit params
			extraParams: {
				
				},
			reader: {
				type: 'json',
				root: 'items',
				totalProperty: 'total'
			}
		}
	});
	
	var saAddonStore = Ext.create('Ext.data.Store', {
		id:'saAddonStore',
		autoLoad: true,
	    model: 'LAAddon',
		pageSize: 100, // items per page
		autoSave: true,
		proxy: {
			type: 'ajax',
			url:'addons/saGrid.action',  // url that will load data with respect to User and limit params
			extraParams: {
				
				},
			reader: {
				type: 'json',
				root: 'items',
				totalProperty: 'total'
			}
		}
	});
	
	var laTamStore = Ext.create('Ext.data.Store', {
		id:'laTamStore',
		autoLoad: true,
	    model: 'LATam',
		pageSize: 100, // items per page
		autoSave: true,
		proxy: {
			type: 'ajax',
			url:'tam/laGrid.action',  // url that will load data with respect to User and limit params
			extraParams: {
				
				},
			reader: {
				type: 'json',
				root: 'items',
				totalProperty: 'total'
			}
		}
	});
	
	var saTamStore = Ext.create('Ext.data.Store', {
		id:'saTamStore',
		autoLoad: true,
	    model: 'LATam',
		pageSize: 100, // items per page
		autoSave: true,
		proxy: {
			type: 'ajax',
			url:'tam/saGrid.action',  // url that will load data with respect to User and limit params
			extraParams: {
				
				},
			reader: {
				type: 'json',
				root: 'items',
				totalProperty: 'total'
			}
		}
	});
	
	
	var toolBarlaTamGrid = Ext.create('Ext.toolbar.Toolbar', {
		region: 'north',
		height: 32, // give north and south regions a height
		items: [{
			text   : "Save Modifications",
			handler: function() {
				var data = [];
				laTamStore.each(function(rec){
				    data.push(rec.get('type'));
				    data.push(rec.get('text'));
				    data.push(rec.get('enable'));
				});
				Ext.Ajax.request({
					url: 'tam/laGrid.action',
					params: { data:data
							},
					success: function(response,options) 
					{ 
					},
					failure: function(response,options) 
					{ 
					}
				});
			}
			},
		        {
		        	xtype: 'splitbutton',
		        	text : 'Create New Tool And Material',
		        	menu: [{
		        		text: 'Learning Object',
		        		id: 'lObject',
		        		iconCls:'',
		        		handler: function(){
		        			newLearningObject.getForm().reset();
		        			newLearningObjectWin.show();
		        			renderTo: Ext.getBody();
		        		}
		        	},{
		        		text: 'Forum Service',
		        		id: 'fService',
		        		iconCls:'',
		        		handler: function(){
		        			newForumService.getForm().reset();
		        			newForumServiceWin.show();
		        			renderTo: Ext.getBody();
		        		}
		        	},{
		        		text: 'Announcement Service',
		        		id: 'aService',
		        		iconCls:'',
		        		handler: function(){
		        			newAnnouncementService.getForm().reset();
		        			newAnnouncementServiceWin.show();
		        			renderTo: Ext.getBody();
		        		}
		        	},{
		        		text: 'Chat Service',
		        		id: 'cService',
		        		iconCls:'',
		        		handler: function(){
		        			newChatService.getForm().reset();
		        			newChatServiceWin.show();
		        			renderTo: Ext.getBody();
		        		}
		        	},{
		        		text: 'Send Mail Service',
		        		id: 'smService',
		        		iconCls:'',
		        		handler: function(){
		        			newSentMail.getForm().reset();
		        			newSentMailWin.show();
		        			renderTo: Ext.getBody();
		        		}
		        	}
		        ]},{
					text   : "Reload Grid",
					handler: function() {
							laTamStore.load();
						}
					}]
	});
	
	var toolBarsaTamGrid = Ext.create('Ext.toolbar.Toolbar', {
		region: 'north',
		height: 32, // give north and south regions a height
		items: [{
			text   : "Save Modifications",
			handler: function() {
				var data = [];
				saTamStore.each(function(rec){
				    data.push(rec.get('type'));
				    data.push(rec.get('text'));
				    data.push(rec.get('enable'));
				});
				Ext.Ajax.request({
					url: 'tam/saGrid.action',
					params: { data:data
							},
					success: function(response,options) 
					{ 
					},
					failure: function(response,options) 
					{ 
					}
				});
			}
			},
		        {
		        	xtype: 'splitbutton',
		        	text : 'Create New Tool And Material',
		        	menu: [{
		        		text: 'Learning Object',
		        		id: 'lObject',
		        		iconCls:'',
		        		handler: function(){
		        			newLearningObject.getForm().reset();
		        			newLearningObjectWin.show();
		        			renderTo: Ext.getBody();
		        		}
		        	},{
		        		text: 'Forum Service',
		        		id: 'fService',
		        		iconCls:'',
		        		handler: function(){
		        			newForumService.getForm().reset();
		        			newForumServiceWin.show();
		        			renderTo: Ext.getBody();
		        		}
		        	},{
		        		text: 'Announcement Service',
		        		id: 'aService',
		        		iconCls:'',
		        		handler: function(){
		        			newAnnouncementService.getForm().reset();
		        			newAnnouncementServiceWin.show();
		        			renderTo: Ext.getBody();
		        		}
		        	},{
		        		text: 'Chat Service',
		        		id: 'cService',
		        		iconCls:'',
		        		handler: function(){
		        			newChatService.getForm().reset();
		        			newChatServiceWin.show();
		        			renderTo: Ext.getBody();
		        		}
		        	},{
		        		text: 'Send Mail Service',
		        		id: 'smService',
		        		iconCls:'',
		        		handler: function(){
		        			newSentMail.getForm().reset();
		        			newSentMailWin.show();
		        			renderTo: Ext.getBody();
		        		}
		        	}
		        ]},{
					text   : "Reload Grid",
					handler: function() {
							saTamStore.load();
						}
					}]
	});
	
	var toolBarlaAddonGrid = Ext.create('Ext.toolbar.Toolbar', {
		region: 'north',
		height: 32, // give north and south regions a height
		items: [{
			text   : "Save Modifications",
			handler: function() {
				var data = [];
				laAddonStore.each(function(rec){
				    data.push(rec.get('type'));
				    data.push(rec.get('text'));
				    data.push(rec.get('enable'));
				});
				Ext.Ajax.request({
					url: 'addons/laGrid.action',
					params: { data:data
							},
					success: function(response,options) 
					{ 
					},
					failure: function(response,options) 
					{ 
					}
				});
			}
			},
		        {
		        	xtype: 'splitbutton',
		        	text : 'Create New Addon',
		        	menu: [{
		        		text: 'TextWork',
		        		id: 'TextWork',
		        		iconCls:'textwork',
		        		handler: function(){
		        			newTextAdd.getForm().reset();
               			 	newTextAddWin.show();
		        			renderTo: Ext.getBody();
		        		}
		        	},{
		        		text: 'Uploading Files',
		        		id: 'uploadingFiles',
		        		iconCls:'upload',
		        		handler: function(){
		        			newUFAdd.getForm().reset();
               			 	newUFAddWin.show();
		        			renderTo: Ext.getBody();
		        		}
		        	},{
		        		text: 'Question and Answers',
		        		id: 'qnas',
		        		iconCls:'qna',
		        		handler: function(){
		        			newQnRAdd.getForm().reset();
               			 	newQnRAddWin.show();
		        			renderTo: Ext.getBody();
		        		}
		        	},{
		        		text: 'Multiple-choice Test',
		        		id: 'mcts',
		        		iconCls:'multiplechoice',
		        		handler: function(){
		        			newMtCAdd.getForm().reset();
               			 	newMtCAddWin.show();
		        			renderTo: Ext.getBody();
		        		}
		        	}
		        ]},{
					text   : "Reload Grid",
					handler: function() {
							laAddonStore.load();
						}
					}]
	});
	
	var laAddonGrid = Ext.create('Ext.grid.Panel', {
		title: 'Addon-ons',
		store: laAddonStore,
		resizable:false,
		plain: true,
		columns: [{header: 'Id', dataIndex: 'id', width:10, flex:1},
		          {header: 'Type', dataIndex: 'type', width:40, flex:2},
		          {header: 'Name', dataIndex: 'text', width:80, flex:3},
		          {xtype: 'checkcolumn', header: 'Include', dataIndex: 'enable', width: 60 }
          ],
          selModel: {  selType: 'cellmodel'},
          plugins: [cellEditing],
          tbar: [ toolBarlaAddonGrid ],
				width: 400,
		        height: 310
	});
	
	
	var toolBarsaAddonGrid = Ext.create('Ext.toolbar.Toolbar', {
		region: 'north',
		height: 32, // give north and south regions a height
		items: [{
			text   : "Save Modifications",
			handler: function() {
				var data = [];
				saAddonStore.each(function(rec){
				    data.push(rec.get('type'));
				    data.push(rec.get('text'));
				    data.push(rec.get('enable'));
				});
				Ext.Ajax.request({
					url: 'addons/saGrid.action',
					params: { data:data
							},
					success: function(response,options) 
					{ 
					},
					failure: function(response,options) 
					{ 
					}
				});
			}
			},
		        {
		        	xtype: 'splitbutton',
		        	text : 'Create New Addon',
		        	menu: [{
		        		text: 'TextWork',
		        		id: 'TextWork',
		        		iconCls:'textwork',
		        		handler: function(){
		        			newTextAdd.getForm().reset();
               			 	newTextAddWin.show();
		        			renderTo: Ext.getBody();
		        		}
		        	},{
		        		text: 'Uploading Files',
		        		id: 'uploadingFiles',
		        		iconCls:'upload',
		        		handler: function(){
		        			newUFAdd.getForm().reset();
               			 	newUFAddWin.show();
		        			renderTo: Ext.getBody();
		        		}
		        	},{
		        		text: 'Question and Answers',
		        		id: 'qnas',
		        		iconCls:'qna',
		        		handler: function(){
		        			newQnRAdd.getForm().reset();
               			 	newQnRAddWin.show();
		        			renderTo: Ext.getBody();
		        		}
		        	},{
		        		text: 'Multiple-choice Test',
		        		id: 'mcts',
		        		iconCls:'multiplechoice',
		        		handler: function(){
		        			newMtCAdd.getForm().reset();
               			 	newMtCAddWin.show();
		        			renderTo: Ext.getBody();
		        		}
		        	}
		        ]},{
					text   : "Reload Grid",
					handler: function() {
							saAddonStore.load();
						}
					}]
	});
	
	var saAddonGrid = Ext.create('Ext.grid.Panel', {
		title: 'Addon-ons',
		store: saAddonStore,
		resizable:false,
		plain: true,
		columns: [{header: 'Id', dataIndex: 'id', width:10, flex:1},
		          {header: 'Type', dataIndex: 'type', width:40, flex:2},
		          {header: 'Name', dataIndex: 'text', width:80, flex:3},
		          {xtype: 'checkcolumn', header: 'Include', dataIndex: 'enable', width: 60 }
          ],
          selModel: {  selType: 'cellmodel'},
          plugins: [cellEditing],
          tbar: [ toolBarsaAddonGrid ],
				width: 400,
		        height: 310
	});
	
	
	var laTamGrid = Ext.create('Ext.grid.Panel', {
		title: 'Tools And Materials',
		store: laTamStore,
		resizable:false,
		plain: true,
		columns: [{header: 'Id', dataIndex: 'id', width:10, flex:1},
		          {header: 'Type', dataIndex: 'type', width:40, flex:2},
		          {header: 'Name', dataIndex: 'text', width:80, flex:3},
		          {xtype: 'checkcolumn', header: 'Include', dataIndex: 'enable', width: 60 }
          ],
          selModel: {  selType: 'cellmodel'},
          plugins: [cellEditing],
          tbar: [ toolBarlaTamGrid ],
				width: 400,
		        height: 310
	});
	
	var saTamGrid = Ext.create('Ext.grid.Panel', {
		title: 'Tools And Materials',
		store: saTamStore,
		resizable:false,
		plain: true,
		columns: [{header: 'Id', dataIndex: 'id', width:10, flex:1},
		          {header: 'Type', dataIndex: 'type', width:40, flex:2},
		          {header: 'Name', dataIndex: 'text', width:80, flex:3},
		          {xtype: 'checkcolumn', header: 'Include', dataIndex: 'enable', width: 60 }
          ],
          selModel: {  selType: 'cellmodel'},
          plugins: [cellEditing],
          tbar: [ toolBarsaTamGrid ],
				width: 400,
		        height: 310
	});
	
    Ext.define('userModsAndMansStore', {
        extend: 'Ext.data.Model',
        fields: [
            // the 'name' below matches the tag name to read, except 'availDate'
            // which is mapped to the tag 'availability'
            {name: 'text', type: 'string'}
        ]
    });
	
	var userModsAndMansStore = Ext.create('Ext.data.Store', {
		id:'userStore1',
		autoLoad: true,
	    model: 'userModsAndMansStore',//fields:['roleName','participant','observer'],
		pageSize: 10, // items per page
		autoSave: true,
		proxy: {
			type: 'ajax',
			url:'tam/getAllRoles.action',  // url that will load data with respect to User and limit params
			extraParams: {	},
			reader: {
				type: 'json',
				root: 'items',
				totalProperty: 'total'
			}
		}
	});
	
	var states = Ext.create('Ext.data.Store', {
	    fields: ['abbr', 'name'],
	    data : [
	        {"abbr":"0", "name":"None"},
	        {"abbr":"1", "name":"User Choice"},
	        {"abbr":"2", "name":"Time Limit"}
	    ]
	});    
	var learningActivityForm = new Ext.FormPanel({
		id:'learningActivityAttribute-form'
		,frame:true
		,width:400
		,height:300
		,url: "activity/saveLearningActivityAttributes.action"
			,items:[{
					defaults:{layout:'fit'}
					,xtype:'tabpanel'
					,items:[{
						xtype: 'form',
						title: 'Description',
						collapsible: true,
						defaultType: 'textfield',
						layout: 'anchor',
						height: 310,
						width: 300,
						items: [{
							xtype: 'htmleditor',
							name: 'description',
							id: 'description',
							height: 280,
							anchor: '100%'
						},{
							xtype: 'button',
							name: 'addResources',
							text: 'Add Resources',
							id: 'addResources',
							handler:function() {
								learningActivityAddResourceLADescriptionWin.show();
				       	  }
						},{
							xtype: 'button',
							name: 'viewResources',
							text: 'View/Edit Resources',
							id: 'viewResources',
							handler:function() {
								storeFilesLADescription.load();
								viewFilesLADescriptionWin.show();
				       	  }
						}]
						},laTamGrid,//,laAddonGrid
						{	title:'Finishing this Activity',
							defaultType: 'textfield',
							layout: 'anchor',
							id:'radios',
							height: 310,
							width: 300,
							defaults: {
								anchor: 'right',
								labelWidth: 100
							}
							// fields
							,items:[
								{
									xtype: 'combo',
									    fieldLabel: 'Finishing Activity',
									    store: states,
									    name: 'effort11',
										id: 'effort11',
									    queryMode: 'local',
									    displayField: 'name',
									    valueField: 'abbr',
									    listeners: {
									        select: function(combo, record, index) {
									          
									          if(record[0].data.abbr=="2"){
									        	 Ext.getCmp('learningActivityAttribute-form').getForm()._fields.items[2].show(true);
									          	 Ext.getCmp('learningActivityAttribute-form').getForm()._fields.items[3].show(true);
									          }else{
									        	 Ext.getCmp('learningActivityAttribute-form').getForm()._fields.items[2].hide(true);
										         Ext.getCmp('learningActivityAttribute-form').getForm()._fields.items[3].hide(true);
									          }
									        }
									      }
								},
						        {
						        	xtype: 'datefield',
					                format: 'd/m/Y',
					                fieldLabel: 'Date',
					                name: 'datefield1',
									id: 'datefield1',
					                width: 140,
					                hidden:true
						        	},
						        	{
						        		xtype: 'timefield',
						                format: 'H:i',
						                fieldLabel: 'Time',
						                name: 'timefield1',
										id: 'timefield1',
						                width: 130,
						                hidden:true
						        	},
								{
									xtype: 'combo',
									fieldLabel: 'Manager',
									name: 'manager',
									id: 'manager',
									editable: false,
									mode: 'local',
									width:120,
									listWidth: 120,
									hiddenName: 'my_dropdown',
									store: userModsAndMansStore
									},
									{  
							            xtype: 'checkbox', //defining the type of component  
							            fieldLabel: 'Is this activity Visible?',//assigning a label  
							            name: 'chk-active', //and a "name" so we can retrieve it in the server...  
							            id: 'id-active'// ...when the form is sent  
							        }
								]

					},{
						xtype: 'form',
						title: 'Learning Objectives',
						collapsible: true,
						defaultType: 'textfield',
						layout: 'anchor',
						height: 310,
						width: 300,
						items: [{
							xtype: 'htmleditor',
							name: 'descriptionObjectives',
							id: 'descriptionObjectives',
							height: 280,
							anchor: '100%'
						},{
							xtype: 'button',
							name: 'addResources',
							text: 'Add Resources',
							id: 'addResources',
							handler:function() {
								learningActivityAddResourceLAObjectiveWin.show();
				       	  }
						},{
							xtype: 'button',
							name: 'viewResources',
							text: 'View/Edit Resources',
							id: 'viewResources',
							handler:function() {
								storeFilesLAObjective.load();
								viewFilesLAObjectiveWin.show();
				       	  }
						}]
						},{
							xtype: 'form',
							title: 'Prerequisites',
							collapsible: true,
							defaultType: 'textfield',
							layout: 'anchor',
							height: 310,
							width: 300,
							items: [{
								xtype: 'htmleditor',
								name: 'descriptionPrerequisites',
								id: 'descriptionPrerequisites',
								height: 280,
								anchor: '100%'
							},{
								xtype: 'button',
								name: 'addResources',
								text: 'Add Resources',
								id: 'addResources',
								handler:function() {
									learningActivityAddResourceLAPrerequisitesWin.show();
					       	  }
							},{
								xtype: 'button',
								name: 'viewResources',
								text: 'View/Edit Resources',
								id: 'viewResources',
								handler:function() {
									storeFilesLAPrerequisites.load();
									viewFilesLAPrerequisitesWin.show();
					       	  }
							}]
							}]
					}]
				,buttonAlign:'right'
				,buttons:[
				          {text:'Cancel',
				        	  handler:function() {
				        		  learningActivityWin.hide();
				        		  Ext.getCmp('learningActivityAttribute-form').getForm().reset();
				       	  }},
				       	  {text:'Update' ,
				       		  handler:function() {
				       			  Ext.getCmp('learningActivityAttribute-form').getForm().submit(
			        					  {//params:{description : Ext.getCmp('learningActivityAttribute-form').getForm()._fields.items[0],
			        						//  effort11 : Ext.getCmp('learningActivityAttribute-form').getForm()._fields.items[1],
			        						//  manager : Ext.getCmp('learningActivityAttribute-form').getForm()._fields.items[2],
			        						//  chkactive : Ext.getCmp('learningActivityAttribute-form').getForm()._fields.items[3],
			        						//  descriptionObjectives : Ext.getCmp('learningActivityAttribute-form').getForm()._fields.items[4],
			        						//  descriptionPrerequisites : Ext.getCmp('learningActivityAttribute-form').getForm()._fields.items[5]},
				       						  waitMsg: 'Updating Learning Activity Attributes...',
				       						  success: function(response) 
				       						  { 
				       							learningActivityWin.hide();
				       						  },
					        				  failure: function(form, action) {
					        					  Ext.Msg.alert('Error', 'Failed editing Learning Activity'); 
					        					  learningActivityWin.hide();
					        				  }
					        			 });
				       			Ext.getCmp('radios').getForm().submit(
			        					  {
				       						  waitMsg: 'Updating Learning Activity Attributes...',
				       						  success: function(response) 
				       						  { 
				       							learningActivityWin.hide();
				       							Ext.getCmp('learningActivityAttribute-form').getForm().reset();
				       						  },
					        				  failure: function(form, action) {
					        					  Ext.Msg.alert('Error', 'Failed editing Learning Activity'); 
					        					  Ext.getCmp('learningActivityAttribute-form').getForm().reset();
					        					  learningActivityWin.hide();
					        				  }
					        			 });
				       			Ext.getCmp('learningActivityAttribute-form').getForm().reset();
				       			Ext.getCmp('radios').getForm().reset();
				       			learningActivityWin.hide();
					        		  }
					        	  }	        	   
					        	  ]
				});
	
    Ext.define('SupportedRoles', {
        extend: 'Ext.data.Model',
        fields: [{name: 'roleName', type: 'string'},
                 {name: 'supportedRole', type: 'bool'}
        ]
    });
    
    
	Activity.prototype.onDoubleClick=function(){
		 
		Ext.Ajax.request({
			url: 'graph/save.action',
			success: function(response,options) 
			{ 
				activityId="Activity:"+this.id;
				
				Ext.getCmp("Export").disable(true);
				var addon123 = Ext.decode(response.responseText);
				var learningActivityForm11 = learningActivityForm.getForm();
				learningActivityForm11._fields.items[0].value=addon123.act.description;
//				if(addon123.act.author != null){
//					learningActivityForm11._fields.items[4].store.data.items[0].data.text=addon123.act.author.text;
//				}
				learningActivityForm11._fields.items[5].setValue(addon123.act.visible);
//				learningActivityForm11._fields.items[6].value=addon123.act.descriptionObjective;
//				learningActivityForm11._fields.items[7].value=addon123.act.descriptionPrerequisites;
				
//				if(addon123.finishingActivity == "NONE"){
//					learningActivityForm11._fields.items[1].setValue(true);
//					learningActivityForm11._fields.items[2].setValue(false);
//					learningActivityForm11._fields.items[3].setValue(false);
//				}else if(addon123.finishingActivity == "USERCHOICE"){
//					learningActivityForm11._fields.items[1].setValue(false);
//					learningActivityForm11._fields.items[2].setValue(true);
//					learningActivityForm11._fields.items[3].setValue(false);
//				} else{
//					learningActivityForm11._fields.items[1].setValue(false);
//					learningActivityForm11._fields.items[2].setValue(false);
//					learningActivityForm11._fields.items[3].setValue(true);
//				}
				learningActivityWin.show();
			},
			params: { htmlCode: new XMLSerializer_01().toXML(workflow),
				activityId:"Activity:"+this.id},
			failure: function(response,options) 
			{ 
			}
		});
		
};





	var userSupportActivityStore = Ext.create('Ext.data.Store', {
		id:'userSupportActivityStore',
		autoLoad: true,
	    model: 'SupportedRoles',
		pageSize: 10, // items per page
		autoSave: true,
		proxy: {
			type: 'ajax',
			url:'act/suportActivityStoreGrid.action',  // url that will load data with respect to User and limit params
			extraParams: {
				asd:getTamTextNode(),
				ddddd:getTamTextParentNode()
				},
			reader: {
				type: 'json',
				root: 'items',
				totalProperty: 'total'
			}
		}
	});


	var userSupportActivityGrid = Ext.create('Ext.grid.Panel', {
		title: 'Supported Roles',
		store: userSupportActivityStore,
		resizable:false,
		plain: true,
		columns: [{header: 'Role', dataIndex: 'roleName', width:50, flex:1},
		          {xtype: 'checkcolumn', header: 'Supported Roles', dataIndex: 'supportedRole', width: 65 }
          ],
          selModel: {  selType: 'cellmodel'},
          plugins: [cellEditing],
          tbar: [{
				text   : "Save Modifications",
				handler: function() {
					var data = [];
					userSupportActivityStore.each(function(rec){
					    data.push(rec.get('roleName'));
					    data.push(rec.get('supportedRole'));
					});
					Ext.Ajax.request({
						url: 'act/suportActivityStoreGrid.action',
						params: { dataFromGrid:data 
								},
						success: function(response,options) 
						{ 
						},
						failure: function(response,options) 
						{ 
						}
					});
				}
				},{
					text   : "Reload",
					handler: function() {
						userSupportActivityStore.load();
						}
				}],
					
				width: 400,
		        height: 310,
          dockedItems: [{
        	  xtype: 'pagingtoolbar',
        	  store: userSupportActivityStore,   // same store GridPanel is using
        	  dock: 'bottom',
        	  displayInfo: false
          }]
	});
	
	var newOneToTwoRole = new Ext.FormPanel({ 
		url:'role/OneToTwoRole.action', 
		id: 'OneToTwoRole-form',
		 defaults: {
	            anchor: '80%',
	            allowBlank: false,
	            msgTarget: 'side'
	        },
		frame:true, 
		items:[{
			xtype: 'combo',
			fieldLabel: 'Select user for activities',
			name: 'user1',
			id: 'user1',
			editable: false,
			mode: 'local',
			width:285,
			labelWidth: 150,
			listWidth: 120,
			hiddenName: 'my_dropdown',
			store: userModsAndMansStore
			}
],
		buttons:[{ 
			text:'Cancel',
			handler:function(){ 
				newOneToTwoRoleWin.hide();
			} 
		},{ 
			text:'Save',
			formBind: true,	 
			handler:function() {
				Ext.getCmp('OneToTwoRole-form').getForm().submit(
						{params:{cmd:'submit',activityId:activityId},
							waitMsg: 'Submiting selected Role...',
							success: function(response, rolesTree) 
							{ 
								newOneToTwoRole.getForm().reset();
								newOneToTwoRoleWin.hide();
							}
						,
						failure: function(form, action) {
							Ext.Msg.alert('Error', 'Failed selecting Role'); 
							newOneToTwoRoleWin.hide();
						}
						});
			}
		}] 
	});
	
	
	var newOneToTwoRoleWin = new Ext.Window({
		layout:'fit',
		title: 'Selection point for Role',
		width:320,
		height:80,
		closable: false,
		resizable: false,
		plain: true,
		border: false,
		items: [newOneToTwoRole]
	});
	
	OneToTwo.prototype.onDoubleClick=function(){
		activityId="OneToTwo:"+this.id;
				
		Ext.Ajax.request({
			url: 'graph/save.action',
			success: function(response,options) 
			{ 				
				newOneToTwoRoleWin.show();
			},
			params: { htmlCode: new XMLSerializer_01().toXML(workflow),
				activityId:"OneToTwo:"+this.id},
			failure: function(response,options) 
			{ 
			}
		});
};
	
	var supportActivityForm = new Ext.FormPanel({
		id:'supportActivityAttribute-form'
		,frame:true
		,width:400
		,height:300
		,url: "activity/saveSupportActivityAttributes.action"
			,items:[{
					defaults:{layout:'fit'}
					,xtype:'tabpanel'
					,items:[{
						xtype: 'form',
						title: 'Description',
						collapsible: true,
						defaultType: 'textfield',
						layout: 'anchor',
						height: 310,
						width: 300,
						items: [{
							xtype: 'htmleditor',
							name: 'description',
							id: 'description',
							height: 280,
							anchor: '100%'
						},{
							xtype: 'button',
							name: 'addResources',
							text: 'Add Resources',
							id: 'addResources',
							handler:function() {
								supportActivityAddResourceSADescriptionWin.show();
				       	  }
						},{
							xtype: 'button',
							name: 'viewResources',
							text: 'View/Edit Resources',
							id: 'viewResources',
							handler:function() {
								storeFilesSADescription.load();
								viewFilesSADescriptionWin.show();
				       	  }
						}]
						},saTamGrid,//saAddonGrid,
						{	title:'Finishing this Activity',
							defaultType: 'textfield',
							layout: 'anchor',
							id:'radios1',
							height: 310,
							width: 300,
							defaults: {
								anchor: 'right',
								labelWidth: 100
							}
							// fields
							,items:[
								{
									xtype: 'combo',
									    fieldLabel: 'Finishing Activity',
									    store: states,
									    name: 'effort11',
										id: 'effort11',
									    queryMode: 'local',
									    displayField: 'name',
									    valueField: 'abbr',
									    listeners: {
									        select: function(combo, record, index) {
									          
									          if(record[0].data.abbr=="2"){
									        	 Ext.getCmp('supportActivityAttribute-form').getForm()._fields.items[2].show(true);
									          	 Ext.getCmp('supportActivityAttribute-form').getForm()._fields.items[3].show(true);
									          }else{
									        	 Ext.getCmp('supportActivityAttribute-form').getForm()._fields.items[2].hide(true);
										         Ext.getCmp('supportActivityAttribute-form').getForm()._fields.items[3].hide(true);
									          }
									        }
									      }
								},
						        {
						        	xtype: 'datefield',
					                format: 'd/m/Y',
					                fieldLabel: 'Date',
					                name: 'datefield1',
									id: 'datefield1',
					                width: 140,
					                hidden:true
						        	},
						        	{
						        		xtype: 'timefield',
						                format: 'H:i',
						                fieldLabel: 'Time',
						                name: 'timefield1',
										id: 'timefield1',
						                width: 130,
						                hidden:true
						        	},{
									xtype: 'combo',
									fieldLabel: 'Manager',
									name: 'manager1',
									id: 'userRole1',
									editable: false,
									mode: 'local',
									width:120,
									listWidth: 120,
									hiddenName: 'my_dropdown',
									store: userModsAndMansStore
									},
									{  
							            xtype: 'checkbox', //defining the type of component  
							            fieldLabel: 'Is this activity Visible?',//assigning a label  
							            name: 'chk-active', //and a "name" so we can retrieve it in the server...  
							            id: 'id-active'// ...when the form is sent  
							        }  
								]

					},userSupportActivityGrid]
					}]
				,buttonAlign:'right'
				,buttons:[
				          {text:'Cancel',
				        	  handler:function() {
				        		  supportActivityWin.hide();
				       	  }},
				       	  {text:'Update' ,
				       		  handler:function() {
				       			  Ext.getCmp('supportActivityAttribute-form').getForm().submit(
			        					  {
				       						  waitMsg: 'Updating Support Activity Attributes...',
				       						  success: function(response) 
				       						  { 
				       							supportActivityWin.hide();
				       						  },
					        				  failure: function(form, action) {
					        					  Ext.Msg.alert('Error', 'Failed editing Learning Activity'); 
					        					  supportActivityWin.hide();
					        				  }
					        			 });
				       			Ext.getCmp('radios1').getForm().submit(
			        					  {
				       						  waitMsg: 'Updating Support Activity Attributes...',
				       						  success: function(response) 
				       						  { 
				       							supportActivityWin.hide();
				       						  },
					        				  failure: function(form, action) {
					        					  Ext.Msg.alert('Error', 'Failed editing Learning Activity'); 
					        					  supportActivityWin.hide();
					        				  }
					        			 });
				       			Ext.getCmp('supportActivityAttribute-form').getForm().reset();
				       			Ext.getCmp('radios1').getForm().reset();
					        		  }
				       
					        	  }	        	   
					        	  ]
				});
	
	SupportActivity.prototype.onDoubleClick=function(){
		Ext.Ajax.request({
			url: 'graph/save.action',
			success: function(response,options) 
			{ 
				activityId="Support:"+this.id;
				supportActivityForm.getForm().reset();
				Ext.getCmp("Export").disable(true);
				var addon123 = Ext.decode(response.responseText);
				var learningActivityForm12 = supportActivityForm.getForm();
				learningActivityForm12.reset();
				learningActivityForm12._fields.items[0].value=addon123.act.description;
//				if(addon123.act.author != null){
//					learningActivityForm11._fields.items[4].store.data.items[0].data.text=addon123.act.author.text;
//				}
//				learningActivityForm12._fields.items[5].setValue(addon123.act.visible);
//				
//				if(addon123.finishingActivity == "NONE"){
//					learningActivityForm12._fields.items[1].setValue(true);
//					learningActivityForm12._fields.items[2].setValue(false);
//					learningActivityForm12._fields.items[3].setValue(false);
//				}else if(addon123.finishingActivity == "USERCHOICE"){
//					learningActivityForm12._fields.items[1].setValue(false);
//					learningActivityForm12._fields.items[2].setValue(true);
//					learningActivityForm12._fields.items[3].setValue(false);
//				} else{
//					learningActivityForm12._fields.items[1].setValue(false);
//					learningActivityForm12._fields.items[2].setValue(false);
//					learningActivityForm12._fields.items[3].setValue(true);
//				}
				supportActivityWin.show();
			},
			params: { htmlCode: new XMLSerializer_01().toXML(workflow),
				activityId:"Support:"+this.id},
			failure: function(response,options) 
			{ 
			}
		});
	};
	
	

	
	var learningObjectForm = new Ext.FormPanel({
		xtype:'form'
		,id:'learningObject-form'
		,defaultType:'textfield'
		,frame:true
		,url: "tam/saveLearningObject.action"
		,defaults:{anchor:'95%'}
		,items:[{
			fieldLabel:'Title'
			,id:'title'
			,name:'title'
			,readOnly : true
		},{
			xtype: 'fieldset',
			title: 'Description',
			collapsible: true,
			defaultType: 'textfield',
			layout: 'anchor',
			defaults: {
				anchor: 'right',
				labelWidth: 300
			},
			items: [{
				xtype: 'htmleditor',
				name: 'description',
				id: 'description',
				height: 200,
				anchor: '100%'
			}]
			}]
				,buttonAlign:'right'
				,buttons:[
				          {text:'Cancel',
				        	  handler:function() {
				        		  learningObjectWin.hide();
				       	  }},
				       	  {text:'Update' ,
				       		  handler:function() {
				       			  Ext.getCmp('learningObject-form').getForm().submit(
				      					  {
				       						  waitMsg: 'Updating Learning Object...',
				       						  success: function(response) 
				       						  { 
				       							learningObjectWin.hide();
				       						  },
					        				  failure: function(form, action) {
					        					  Ext.Msg.alert('Error', 'Failed editing learning object attributes'); 
					        					  learningObjectWin.hide();
					        				  }
					        			 });
					        		  }
					        	  }	        	   
					        	  ]
				});
	var tit = getTitle();
    Ext.define('Plant', {
        extend: 'Ext.data.Model',
        fields: [{name: 'roleName', type: 'string'},
                 {name: 'participant', type: 'bool'},
                 {name: 'observer', type: 'bool'}
        ]
    });


	var userfsStore = Ext.create('Ext.data.Store', {
			id:'userStore',
			autoLoad: true,
		    model: 'Plant',
			pageSize: 10, // items per page
			autoSave: true,
			proxy: {
				type: 'ajax',
				url:'tam/fsGrid.action',  // url that will load data with respect to User and limit params
				extraParams: {
					asd:getTamTextNode(),
					ddddd:getTamTextParentNode()
					},
				reader: {
					type: 'json',
					root: 'items',
					totalProperty: 'total'
				}
			}
		});
	var userasStore = Ext.create('Ext.data.Store', {
		id:'userStore',
		autoLoad: true,
	    model: 'Plant',
		pageSize: 10, // items per page
		autoSave: true,
		proxy: {
			type: 'ajax',
			url:'tam/asGrid.action',  // url that will load data with respect to User and limit params
			extraParams: {
				asd:getTamTextNode(),
				ddddd:getTamTextParentNode()
				},
			reader: {
				type: 'json',
				root: 'items',
				totalProperty: 'total'
			}
		}
	});
	var usercsStore = Ext.create('Ext.data.Store', {
		id:'userStore',
		autoLoad: true,
	    model: 'Plant',
		pageSize: 10, // items per page
		autoSave: true,
		proxy: {
			type: 'ajax',
			url:'tam/csGrid.action',  // url that will load data with respect to User and limit params
			extraParams: {
				asd:getTamTextNode(),
				ddddd:getTamTextParentNode()
				},
			reader: {
				type: 'json',
				root: 'items',
				totalProperty: 'total'
			}
		}
	});
	var usersmStore = Ext.create('Ext.data.Store', {
		id:'usersmStore',
		autoLoad: true,
	    model: 'Recipient',
		pageSize: 10, // items per page
		autoSave: true,
		proxy: {
			type: 'ajax',
			url:'tam/smGrid.action',  // url that will load data with respect to User and limit params
			extraParams: {
				asd:getTamTextNode(),
				ddddd:getTamTextParentNode()
				},
			reader: {
				type: 'json',
				root: 'items',
				totalProperty: 'total'
			}
		}
	});
	
	
	var userfsGrid = Ext.create('Ext.grid.Panel', {
		title: '',
		store: userfsStore,
		resizable:false,
		plain: true,
		columns: [{header: 'Role', dataIndex: 'roleName', width:50, flex:1},
		          {xtype: 'checkcolumn', header: 'Participant', dataIndex: 'participant', width: 65 },
			      { xtype: 'checkcolumn', header: 'Observer', dataIndex: 'observer', width: 65  }
          ],
          selModel: {  selType: 'cellmodel'},
          plugins: [cellEditing],
          tbar: [{
				text   : "Save Modifications",
				handler: function() {
					var data = [];
					userfsStore.each(function(rec){
					    data.push(rec.get('roleName'));
					    data.push(rec.get('participant'));
					    data.push(rec.get('observer'));
					});
					Ext.Ajax.request({
						url: 'tam/fsGrid.action',
						params: { node:getSelectTextNode(),	dataFromGrid:data 
								},
						success: function(response,options) 
						{ 
						},
						failure: function(response,options) 
						{ 
						}
					});
				}
				}],
				width: 400,
		        height: 175,
          dockedItems: [{
        	  xtype: 'pagingtoolbar',
        	  store: userfsStore,   // same store GridPanel is using
        	  dock: 'bottom',
        	  displayInfo: false
          }]
	});
	
	var userasGrid = Ext.create('Ext.grid.Panel', {
		title: '',
		store: userasStore,
		resizable:false,
		plain: true,
		columns: [{header: 'Role', dataIndex: 'roleName', width:50, flex:1},
		          {xtype: 'checkcolumn', header: 'Participant', dataIndex: 'participant', width: 65 },
			      { xtype: 'checkcolumn', header: 'Observer', dataIndex: 'observer', width: 65  }
          ],
          selModel: {  selType: 'cellmodel'},
          plugins: [cellEditing],
          tbar: [{
				text   : "Save Modifications",
				handler: function() {
					var data = [];
					userasStore.each(function(rec){
					    data.push(rec.get('roleName'));
					    data.push(rec.get('participant'));
					    data.push(rec.get('observer'));
					});
					Ext.Ajax.request({
						url: 'tam/asGrid.action',
						params: { node:getSelectTextNode(),	dataFromGrid:data 
								},
						success: function(response,options) 
						{ 
						},
						failure: function(response,options) 
						{ 
						}
					});
				}
				}],
				width: 400,
		        height: 175,
          dockedItems: [{
        	  xtype: 'pagingtoolbar',
        	  store: userasStore,   // same store GridPanel is using
        	  dock: 'bottom',
        	  displayInfo: false
          }]
	});
	var usercsGrid = Ext.create('Ext.grid.Panel', {
		title: '',
		store: usercsStore,
		resizable:false,
		plain: true,
		columns: [{header: 'Role', dataIndex: 'roleName', width:50, flex:1},
		          {xtype: 'checkcolumn', header: 'Participant', dataIndex: 'participant', width: 65 },
			      { xtype: 'checkcolumn', header: 'Observer', dataIndex: 'observer', width: 65  }
          ],
          selModel: {  selType: 'cellmodel'},
          plugins: [cellEditing],
          tbar: [{
				text   : "Save Modifications",
				handler: function() {
					var data = [];
					usercsStore.each(function(rec){
					    data.push(rec.get('roleName'));
					    data.push(rec.get('participant'));
					    data.push(rec.get('observer'));
					});
					Ext.Ajax.request({
						url: 'tam/csGrid.action',
						params: { node:getSelectTextNode(),	dataFromGrid:data 
								},
						success: function(response,options) 
						{ 
						},
						failure: function(response,options) 
						{ 
						}
					});
				}
				}],
				width: 400,
		        height: 175,
          dockedItems: [{
        	  xtype: 'pagingtoolbar',
        	  store: userfsStore,   // same store GridPanel is using
        	  dock: 'bottom',
        	  displayInfo: false
          }]
	});
	var usersmGrid = Ext.create('Ext.grid.Panel', {
		title: '',
		store: usersmStore,
		resizable:false,
		plain: true,
		columns: [{header: 'Role', dataIndex: 'roleName', width:50, flex:1},
		          {xtype: 'checkcolumn', header: 'Recipient', dataIndex: 'recipient', width: 65 }
          ],
          selModel: {  selType: 'cellmodel'},
          plugins: [cellEditing],
          tbar: [{
				text   : "Save Modifications",
				handler: function() {
					var data = [];
					usersmStore.each(function(rec){
					    data.push(rec.get('roleName'));
					    data.push(rec.get('recipient'));
					});
					Ext.Ajax.request({
						url: 'tam/smGrid.action',
						params: { node:getSelectTextNode(),	dataFromGrid:data 
								},
						success: function(response,options) 
						{ 
						},
						failure: function(response,options) 
						{ 
						}
					});
				}
				}],
				width: 400,
		        height: 175,
          dockedItems: [{
        	  xtype: 'pagingtoolbar',
        	  store: userfsStore,   // same store GridPanel is using
        	  dock: 'bottom',
        	  displayInfo: false
          }]
	});
	
	

	
	var menuUsers = new Ext.menu.Menu({
		id: 'menuUsers', items: [
		                     { text: 'Edit Roles of Participants and Observers' ,
		                    	 iconCls:'add',
		                    	 handler:function(index, event, toolsAndMaterialsTree, node) {
		                    		 if( getSelectTextParentNode().indexOf("Tools & Materials/Forum Service")===0){
		                    			 setTamTextNode(getSelectTextNode());
		                    			 setTamTextParentNode(getSelectTextParentNode());
		                    			 userfsStore.load({url:'tam/fsGrid.action?node='+getSelectTextNode()});
		                    			 openUserfsWin.show();
		                    		 }else if( getSelectTextParentNode().indexOf("Tools & Materials/Announcement Service")===0){
		                    			 setTamTextNode(getSelectTextNode());
		                    			 setTamTextParentNode(getSelectTextParentNode());
		                    			 userasStore.load({url:'tam/asGrid.action?node='+getSelectTextNode()});
		                    			 openUserasWin.show();
		                    		 }else if( getSelectTextParentNode().indexOf("Tools & Materials/Chat Service")===0){
		                    			 setTamTextNode(getSelectTextNode());
			                    		 setTamTextParentNode(getSelectTextParentNode());
			                    		 usercsStore.load({url:'tam/csGrid.action?node='+getSelectTextNode()});
			                    		 openUsercsWin.show();
		                    		 }else{
		                    			 setTamTextNode(getSelectTextNode());
			                    		 setTamTextParentNode(getSelectTextParentNode());
			                    		 usersmStore.load({url:'tam/smGrid.action?node='+getSelectTextNode()});
			                    		 openUsersmWin.show();
		                    		 }
		                    		 
		                    	 }
		                     }
		                     ]
	});
	
	var openUserfsWin = new Ext.Window({
		title: 'Edit Forum Service Roles',
		applyTo:'editfsRoles-win',
		width:410,
		height:238,
		closeAction:'hide',
		resizable:false,
		plain: true,
		items: userfsGrid ,
		buttons: [{
			text: 'Close',
			handler: function(){
				openUserfsWin.hide();
			}
		}]
	});
	var openUserasWin = new Ext.Window({
		title: 'Edit Announcement Service Roles',
		applyTo:'editasRoles-win',
		width:410,
		height:238,
		closeAction:'hide',
		resizable:false,
		plain: true,
		items: userasGrid ,
		buttons: [{
			text: 'Close',
			handler: function(){
				openUserasWin.hide();
			}
		}]
	});
	var openUsercsWin = new Ext.Window({
		title: 'Edit Chat Service Roles',
		applyTo:'editcsRoles-win',
		width:410,
		height:238,
		closeAction:'hide',
		resizable:false,
		plain: true,
		items: usercsGrid ,
		buttons: [{
			text: 'Close',
			handler: function(){
				openUsercsWin.hide();
			}
		}]
	});
	var openUsersmWin = new Ext.Window({
		title: 'Edit Sent Mail Service Roles',
		applyTo:'editcsRoles-win',
		width:410,
		height:238,
		closeAction:'hide',
		resizable:false,
		plain: true,
		items: usersmGrid ,
		buttons: [{
			text: 'Close',
			handler: function(){
				openUsersmWin.hide();
			}
		}]
	});
	

	
	var chatServiceForm = new Ext.FormPanel({
		xtype:'form'
		,id:'chatService-form'
		,defaultType:'textfield'
		,frame:true
		,url: "tam/chatService.action"
		,defaults:{anchor:'95%'}
		,items:[{
			fieldLabel:'Title'
			,id:'title'
			,name:'title'
			,readOnly : true
		},	{
			
					title:'Description',
					xtype: 'htmleditor',
					name: 'decription',
					id: 'decription',
					height: 150,
					anchor: '100%'
				
		},{
				xtype: 'combo',
				fieldLabel: 'Manager',
				name: 'manager',
				editable: false,
				mode: 'local',
				width:120,
				listWidth: 120,
				hiddenName: 'my_dropdown',
				store: userModsAndMansStore
				},
				{
					xtype: 'combo',
					fieldLabel: 'Moderator',
					name: 'moderator',
					editable: false,
					triggerAction: 'all',
					typeAhead: false,
					mode: 'local',
					width:120,
					listWidth: 120,
					hiddenName: 'my_dropdown1',
					store: userModsAndMansStore
					}]
		
				,buttonAlign:'right'
				,buttons:[
				          {text:'Cancel',
				        	  handler:function() {
				        		  chatServiceWin.hide();
				       	  }},
				       	  {text:'Update' ,
				       		  handler:function() {
				       			  Ext.getCmp('chatService-form').getForm().submit(
				      					  {
				       						  waitMsg: 'Updating Chat Service...',
				       						  success: function(response) 
				       						  { 
				       							chatServiceForm.getForm().reset();
				       							chatServiceWin.hide();
				       						  },
					        				  failure: function(form, action) {
					        					  Ext.Msg.alert('Error', 'Failed editing chat service attributes'); 
					        					  chatServiceWin.hide();
					        				  }
					        			 });
					        		  }
					        	  }	        	   
					        	  ]
				});
	
	var announcementServiceForm = new Ext.FormPanel({
		xtype:'form'
		,id:'announcementService-form'
		,defaultType:'textfield'
		,frame:true
		,url: "tam/saveAnnouncementService.action"
		,defaults:{anchor:'95%'}
		,items:[{
			fieldLabel:'Title'
			,id:'title'
			,name:'title'
			,readOnly : true
		},	{
			
					title:'Description',
					xtype: 'htmleditor',
					name: 'decription',
					id: 'decription',
					height: 150,
					anchor: '100%'
				
		},{
				xtype: 'combo',
				fieldLabel: 'Manager',
				name: 'manager',
				editable: false,
				mode: 'local',
				width:120,
				listWidth: 120,
				hiddenName: 'my_dropdown',
				store: userModsAndMansStore
				},
				{
					xtype: 'combo',
					fieldLabel: 'Moderator',
					name: 'moderator',
					editable: false,
					triggerAction: 'all',
					typeAhead: false,
					mode: 'local',
					width:120,
					listWidth: 120,
					hiddenName: 'my_dropdown1',
					store: userModsAndMansStore
					}]
		
				,buttonAlign:'right'
				,buttons:[
				          {text:'Cancel',
				        	  handler:function() {
				        		  announcementServiceWin.hide();
				       	  }},
				       	  {text:'Update' ,
				       		  handler:function() {
				       			  Ext.getCmp('announcementService-form').getForm().submit(
				      					  {
				       						  waitMsg: 'Updating Announcement Service...',
				       						  success: function(response) 
				       						  { 
				       							announcementServiceForm.getForm().reset();
				       							announcementServiceWin.hide();
				       						  },
					        				  failure: function(form, action) {
					        					  Ext.Msg.alert('Error', 'Failed editing announcement service attributes'); 
					        					  announcementServiceWin.hide();
					        				  }
					        			 });
					        		  }
					        	  }	        	   
					        	  ]
				});
	
	
	var forumServiceForm = new Ext.FormPanel({
		xtype:'form'
		,id:'forumService-form'
		,defaultType:'textfield'
		,frame:true
		,url: "tam/saveForumService.action"
		,defaults:{anchor:'95%'}
		,items:[{
			fieldLabel:'Title'
			,id:'title'
			,name:'title'
			,readOnly : true
		},	{
			
					title:'Description',
					xtype: 'htmleditor',
					name: 'decription',
					id: 'decription',
					height: 150,
					anchor: '100%'
				
		},{
				xtype: 'combo',
				fieldLabel: 'Manager',
				name: 'manager',
				editable: false,
				mode: 'local',
				width:120,
				listWidth: 120,
				hiddenName: 'my_dropdown',
				store: userModsAndMansStore
				},
				{
					xtype: 'combo',
					fieldLabel: 'Moderator',
					name: 'moderator',
					editable: false,
					triggerAction: 'all',
					typeAhead: false,
					mode: 'local',
					width:120,
					listWidth: 120,
					hiddenName: 'my_dropdown1',
					store: userModsAndMansStore
					}]
		
				,buttonAlign:'right'
				,buttons:[
				          {text:'Cancel',
				        	  handler:function() {
				        		  forumServiceWin.hide();
				       	  }},
				       	  {text:'Update' ,
				       		  handler:function() {
				       			  Ext.getCmp('forumService-form').getForm().submit(
				      					  {
				       						  waitMsg: 'Updating Forum Service...',
				       						  success: function(response) 
				       						  { 
				       							forumServiceForm.getForm().reset();
				       							forumServiceWin.hide();
				       						  },
					        				  failure: function(form, action) {
					        					  Ext.Msg.alert('Error', 'Failed editing forum service attributes'); 
					        					  forumServiceWin.hide();
					        				  }
					        			 });
					        		  }
					        	  }	        	   
					        	  ]
				});
	
	//////////////////////////////////////////////////////////////////////////////////
	/*                         END  -  FORMS                                        */
	/*                                                                              */
	/*                                                                              */
	//////////////////////////////////////////////////////////////////////////////////

	//////////////////////////////////////////////////////////////////////////////////
	/*                         START  -  WINDOWS                                    */
	/*                                                                              */
	/*                                                                              */
	//////////////////////////////////////////////////////////////////////////////////
	


	var openWinUoL = new Ext.Window({
		title: 'Open Learning Design',
		applyTo:'hello-win',
		width:410,
		height:238,
		closeAction:'hide',
		resizable:true,
		plain: true,
		items: gridUoL ,
		buttons: [{
			text:'Open',
			handler: function(){
				waitMsg: 'Loading...';
		var selModel = gridUoL.getSelectionModel();
		var record = selModel.selected.items[0].data.id;
		var title = selModel.selected.items[0].data.title;
		Ext.Ajax.request({
			url: 'configure/session.action',
			params: {
				id: record
			},
			success: function(response,options) 
			{ 
				workflow.clear();
				var tab  = tabPanel.getActiveTab();
				var responseText = response.responseText;
				var array=responseText.split(",");
				var addon = Ext.decode(response.responseText);
				var parser=new DOMParser();
				var doc=parser.parseFromString(addon.graph,"text/xml");
				var pp = doc.documentElement.children;
				new deserializer_01.prototype.fromXML(pp, workflow);      
				var array2=array[3].split(":");
				tab.setTitle(array2[1]);
				var west = Ext.getCmp('west-panel');
				west.getEl().unmask();
				var east = Ext.getCmp('east-panel');
				east.getEl().unmask();
				var center = Ext.getCmp('center-panel');
				center.getEl().unmask();
				Ext.getCmp('rolesTreeId').getStore().load();
				Ext.getCmp('addonsId').getStore().load();
				//Ext.getCmp('autocompleteUoL').clearValue();
			}
		});
		openWinUoL.hide();
			}

		},{
			text: 'Close',
			handler: function(){
				openWinUoL.hide();
			}
		}]
	});

	
	var sentMailServiceForm = new Ext.FormPanel({
	xtype:'form'
	,id:'sentMailService-form'
	,defaultType:'textfield'
	,frame:true
	,url: "tam/sentMailService.action"
	,defaults:{anchor:'95%'}
	,items:[{
		fieldLabel:'Title'
		,id:'title'
		,name:'title'
		,readOnly : true
	},	{
		xtype: 'fieldset',
		title: 'Specification of Role type for Sent Mail Service',
		collapsible: true,
		defaultType: 'textfield',
		layout: 'anchor',
		defaults: {
			anchor: 'right',
			labelWidth: 300
		},
		items: [{
			xtype: 'radiofield',
			name: 'all',
			id: 'all1',
			fieldLabel: 'All person(s) specified by role will receive the mail ',
			aling: 'right',
			boxLabel: '',
			inputValue: 'ALLPERSONS'
		},{
			xtype: 'radiofield',
			name: 'all',
			id: 'certain1',
			fieldLabel: 'Only certain individuals on the role specified will receive the mail',
			aling: 'right',
			boxLabel: '',
			inputValue: 'INDIVIDUAL'
		}]
	}
		]
	
			,buttonAlign:'right'
				,buttons:[
				          {text:'Cancel',
				        	  handler:function() {
				        		  sentMailServiceWin.hide();
				       	  }},
				       	  {text:'Update' ,
				       		  handler:function() {
				       			  Ext.getCmp('sentMailService-form').getForm().submit(
				      					  {
				       						  waitMsg: 'Updating Sent Mail Service...',
				       						  success: function(response) 
				       						  { 
				       							sentMailServiceForm.getForm().reset();
				       							sentMailServiceWin.hide();
				       						  },
					        				  failure: function(form, action) {
					        					  Ext.Msg.alert('Error', 'Failed editing sent mail attributes'); 
					        					  sentMailServiceWin.hide();
					        				  }
					        			 });
					        		  }
					        	  }	        	   
					        	  ]
				        	  
			});


	var openWin = new Ext.Window({
		title: 'Open Graphs',
		applyTo:'hello-win',
		//layout:'fit',
		width:410,
		height:238,
		closeAction:'hide',
		plain: true,
		items: grid ,
		buttons: [{
			text:'Open',
			handler: function(){
				waitMsg: 'Loading...';
		var selModel = grid.getSelectionModel();
		var record = selModel.selected.items[0].data.id;
		var code = selModel.selected.items[0].data.graphHtml;
		var parser=new DOMParser();
		var doc=parser.parseFromString(code,"text/xml");
		var pp = doc.documentElement.children;
		new deserializer_01.prototype.fromXML(pp, workflow);                	  
		openWin.hide();
			}

		},{
			text: 'Close',
			handler: function(){
				openWin.hide();
			}
		}]
	});

	var newRoleAttributeWin = new Ext.Window({
		//layout:'fit',
		width:520,
		height:500,
		closable: false,
		resizable: true,
		plain: true,
		border: false,
		title:'Edit Role Dialog',
		items:[RoleAttributeForm]
	});


	var newUoLWin = new Ext.Window({
		layout:'fit',
		width:300,
		height:230,
		closable: false,
		resizable: false,
		plain: true,
		border: false,
		title:'Create new Learning Design',
		items:[newUoLForm]
	});


	var newStaffRoleWin = new Ext.Window({
		layout:'fit',
		title: 'Create new Staff Role',
		width:280,
		height:80,
		closable: false,
		resizable: false,
		plain: true,
		border: false,
		items: [newStaffRole]
	});


	var newLearnerRoleWin = new Ext.Window({
		layout:'fit',
		title: 'Create new Learner Role',
		width:280,
		height:80,
		closable: false,
		resizable: false,
		plain: true,
		border: false,
		items: [newLearnerRole]
	});
	


	
	var newOneToTwoRole = new Ext.FormPanel({ 
		url:'role/OneToTwoRole.action', 
		id: 'OneToTwoRole-form',
		 defaults: {
	            anchor: '80%',
	            allowBlank: false,
	            msgTarget: 'side'
	        },
		frame:true, 
		items:[{
			xtype: 'combo',
			fieldLabel: 'Select user for activities',
			name: 'user1',
			id: 'user1',
			editable: false,
			mode: 'local',
			width:285,
			labelWidth: 150,
			listWidth: 120,
			hiddenName: 'my_dropdown',
			store: userModsAndMansStore
			}
],
		buttons:[{ 
			text:'Cancel',
			handler:function(){ 
				newOneToTwoRoleWin.hide();
			} 
		},{ 
			text:'Save',
			formBind: true,	 
			handler:function() {
				Ext.getCmp('OneToTwoRole-form').getForm().submit(
						{params:{cmd:'submit',activityId:activityId},
							waitMsg: 'Submiting selected Role...',
							success: function(response, rolesTree) 
							{ 
								newOneToTwoRole.getForm().reset();
								newOneToTwoRoleWin.hide();
							}
						,
						failure: function(form, action) {
							Ext.Msg.alert('Error', 'Failed selecting Role'); 
							newOneToTwoRoleWin.hide();
						}
						});
			}
		}] 
	});
	
	
	var newOneToTwoRoleWin = new Ext.Window({
		layout:'fit',
		title: 'Selection point for Role',
		width:320,
		height:80,
		closable: false,
		resizable: false,
		plain: true,
		border: false,
		items: [newOneToTwoRole]
	});
	
	OneToTwo.prototype.onDoubleClick=function(){
		activityId="OneToTwo:"+this.id;
				
		Ext.Ajax.request({
			url: 'graph/save.action',
			success: function(response,options) 
			{ 				
				newOneToTwoRoleWin.show();
			},
			params: { htmlCode: new XMLSerializer_01().toXML(workflow),
				activityId:"OneToTwo:"+this.id},
			failure: function(response,options) 
			{ 
			}
		});
};
	
	var newLearningObjectWin = new Ext.Window({
		layout:'fit',
		title: 'Create new Learning Object',
		width:280,
		height:80,
		closable: false,
		resizable: false,
		plain: true,
		border: false,
		items: [newLearningObject]
	});
	
	var newForumServiceWin = new Ext.Window({
		layout:'fit',
		title: 'Create new Forum Service',
		width:280,
		height:80,
		closable: false,
		resizable: false,
		plain: true,
		border: false,
		items: [newForumService]
	});
	
	var newAnnouncementServiceWin = new Ext.Window({
		layout:'fit',
		title: 'Create new Announcement Service',
		width:280,
		height:105,
		closable: false,
		resizable: false,
		plain: true,
		border: false,
		items: [newAnnouncementService]
	});
	
	var newChatServiceWin = new Ext.Window({
		layout:'fit',
		title: 'Create new Chat Service',
		width:280,
		height:80,
		closable: false,
		resizable: false,
		plain: true,
		border: false,
		items: [newChatService]
	});
	
	var newSentMailWin = new Ext.Window({
		layout:'fit',
		title: 'Create new Sent Mail',
		width:280,
		height:80,
		closable: false,
		resizable: false,
		plain: true,
		border: false,
		items: [newSentMail]
	});
	
	var newTextWorkWin = new Ext.Window({
		layout:'fit',
		title: 'Create new Text Work',
		width:480,
		height:240,
		closable: false,
		resizable: false,
		plain: true,
		border: false,
		items: [AddonTextWorkAttributeForm]
	});
	
	var newUploadingFilesWin = new Ext.Window({
		layout:'fit',
		title: 'Create new Uploading Files',
		width:480,
		height:240,
		closable: false,
		resizable: false,
		plain: true,
		border: false,
		items: [AddonUploadingFilesAttributeForm]
	});	
	
	var newQnRWin = new Ext.Window({
		layout:'fit',
		title: 'Create new Question and Answers Addon',
		width:530,
		height:240,
		closable: false,
		resizable: false,
		plain: true,
		border: false,
		items: [AddonQnRAttributeForm]
	});
	
	var newMcTWin = new Ext.Window({
		layout:'fit',
		title: 'Create new Multiple-Choise Test Addon',
		width:430,
		height:170,
		closable: false,
		resizable: false,
		plain: true,
		border: false,
		items: [AddonMcTAttributeForm]
	});
	

	
	var supportActivityWin = new Ext.Window({
		title:'Edit Support Activity Dialog'
		,width:400
		,height:420
		,plain:true
		,closable:false
		,layout:'fit'
		,layoutConfig:{animate:true}
		,border:false
		,items:[supportActivityForm]
		});

	var learningActivityWin = new Ext.Window({
		title:'Edit Learning Activity Dialog'
		,width:400
		,height:420
		,plain:true
		,closable:false
		,layout:'fit'
		,layoutConfig:{animate:true}
		,border:false
		,items:[learningActivityForm]
		});
	
	var learningActivityAddResourceLADescriptionWin = new Ext.Window({
			title:'Add Resource Learning Object Description'
			,width:400
			,height:160
			,plain:true
			,closable:true
			,layout:'fit'
			,layoutConfig:{animate:true}
			,border:false
			,items:[learningActivityAddResourceLADescriptionForm]
	});
	
	var supportActivityAddResourceSADescriptionWin = new Ext.Window({
		title:'Add Resource Learning Object Description'
		,width:400
		,height:160
		,plain:true
		,closable:true
		,layout:'fit'
		,layoutConfig:{animate:true}
		,border:false
		,items:[supportActivityAddResourceSADescriptionForm]
});

	var learningActivityAddResourceLAObjectiveWin = new Ext.Window({
		title:'Add Resource Learning Object Objective'
		,width:400
		,height:160
		,plain:true
		,closable:true
		,layout:'fit'
		,layoutConfig:{animate:true}
		,border:false
		,items:[learningActivityAddResourceLAObjectiveForm]
});
	
	var learningActivityAddResourceLAPrerequisitesWin = new Ext.Window({
		title:'Add Resource Learning Object Prerequisite'
		,width:400
		,height:160
		,plain:true
		,closable:true
		,layout:'fit'
		,layoutConfig:{animate:true}
		,border:false
		,items:[learningActivityAddResourceLAPrerequisitesForm]
});
	
	var importLDWin = new Ext.Window({
		title:'Import Learning Design'
		,width:400
		,height:160
		,plain:true
		,closable:true
		,layout:'fit'
		,layoutConfig:{animate:true}
		,border:false
		,items:[importLDForm]
});
	
	var forumServiceWin = new Ext.Window({
		title:'Edit Forum Service'
		,width:400
		,height:330
		,plain:true
		,closable:false
		,layout:'fit'
		,layoutConfig:{animate:true}
		,border:false
		,items:[forumServiceForm]
});
	
	var announcementServiceWin = new Ext.Window({
		layout:'fit',
		title: 'Edit Announcement Service',
		width:400,
		height:330,
		closable: false,
		resizable: false,
		plain: true,
		border: false,
		items: [announcementServiceForm]
	});
	
	var chatServiceWin = new Ext.Window({
		layout:'fit',
		title: 'Edit Chat Service',
		width:400,
		height:330,
		closable: false,
		resizable: false,
		plain: true,
		border: false,
		items: [chatServiceForm]
	});
	
	var learningObjectWin = new Ext.Window({
		layout:'fit',
		title: 'Edit Learning Object Service',
		width:400,
		height:330,
		closable: false,
		resizable: false,
		plain: true,
		border: false,
		items: [learningObjectForm]
	});
	
	var sentMailServiceWin = new Ext.Window({
		layout:'fit',
		title: 'Edit Sent Mail Service',
		width:420,
		height:180,
		closable: false,
		resizable: false,
		plain: true,
		border: false,
		items: [sentMailServiceForm]
	});

	//////////////////////////////////////////////////////////////////////////////////
	/*                         END  -  WINDOWS                                      */
	/*                                                                              */
	/*                                                                              */
	//////////////////////////////////////////////////////////////////////////////////



	
	var store = Ext.create('Ext.data.Store', {
		id:'simpsonsStore',
		autoLoad: true,
		fields:['id','graphHtml'],
		pageSize: 10, // items per page
		proxy: {
			type: 'ajax',
			url: 'graph/view.action',  // url that will load data with respect to User and limit params
			reader: {
				type: 'json',
				root: 'items',
				totalProperty: 'total'
			}
		}
	});

	var grid = Ext.create('Ext.grid.Panel', {
		title: 'Graphs',
		store: store,
		columns: [
		          {header: 'Title',  dataIndex: 'id', flex:1}//,
		          ],
		          width: 400,
		          height: 175,
		          dockedItems: [{
		        	  xtype: 'pagingtoolbar',
		        	  store: store,   // same store GridPanel is using
		        	  dock: 'bottom',
		        	  displayInfo: true
		          }]//,         renderTo: Ext.getBody()
	}); 









	var tabPanel = Ext.create('Ext.tab.Panel', {
		region: 'center', // a center region is ALWAYS required for border layout
		id : 'center-panel',
		deferredRender: false,
		enableTabScroll: true,
		items: [{
			contentEl: 'center1',
			title: 'Learning Unit',
			autoScroll: true,
			autoHeight:true,
			autoWidth:true
		}]
	});
	


	var menuC = new Ext.menu.Menu({
		id: 'menuC', items: [
		                     { text: 'New Role' ,
		                       iconCls:'add',
		                    	 handler:function(index, event, rolesTree, node) {
		                    		 if( selectedNode == 1){
		                    			 newLearnerRoleWin.show();
		                    		 } else{
		                    			 newStaffRoleWin.show();
		                    		 }

		                    	 }}	 
		                     ]
	});
	
	var menuToolsAndMaterials = new Ext.menu.Menu({
		id: 'menuToolsAndMaterials', items: [
		                     { text: 'New Tools & Materials' ,
		                       iconCls:'add',
		                    	 handler:function(index, event, rolesTree, node) {
		                    		 if( getSelectionNode() == 1){
		                    			 newLearningObjectWin.show();
		                    		 } else if( getSelectionNode() == 2){
		                    			 newForumServiceWin.show();
		                    		 }else if( getSelectionNode() == 3){
		                    			 newAnnouncementServiceWin.show();
		                    		 }else if( getSelectionNode() == 4){
		                    			 newChatServiceWin.show();
		                    		 }else if( getSelectionNode() == 5){
		                    			 newSentMailWin.show();
		                    		 }
		                    	 }}	 
		                     ]
	});
	



	var addonsStore = Ext.create('Ext.data.TreeStore', {
		proxy: {
			type: 'ajax',
			url: 'addons/getTreeaddons.action'
		},
		root: {
			text: 'Add-ons',
			id: 'root',
			iconCls:'addons',
			expanded: true,
			children:[{
				text:'Text work',
				id: 'textwork',
				iconCls:'textwork',
				qtip:'Right click to create a new Text Work'
			},{
				text:'Uploading Files',
				id: 'uploadFiles',
				iconCls:'upload',
				qtip:'Right click to create a new Uploading Files'
			},{
				text:'Question and Answers',
				id: 'qna',
				iconCls:'qna',
				qtip:'Right click to create a new Question and Answers'
			},{
				text:'Multiple-choice Test',
				id: 'mct',
				iconCls:'multiplechoice',
				qtip:'Right click to create a new Multiple Choice Tests'
			}
			]
		}
	});
	
	var addonsTree = new  Ext.create('Ext.tree.TreePanel', {
		title: 'Add-ons',
		store: addonsStore,
		collapsible:true,
		width:300,
		layout:'fit',
		iconCls:'red',
		viewConfig: {
		forceFit:true
		},
		titleCollapse: true,
		id: 'addonsId',
		rootVisible: true,
		lines: false,
		dockedItems: [{
			xtype: 'toolbar',
			items: [ {
				text: 'Refresh',
				iconCls:'refresh',
				handler: function(){
					Ext.getCmp('addonsId').getStore().load();

				}
			}]
		}],
		listeners: {
			dblclick: {
				element: 'body', //bind to the underlying body property on the panel
				fn: function(view, rec, node, index, e){ 
					if(rec.getText() != "Add-ons" && rec.getText() != "Text work" 
							&& rec.getText() != "Uploading Files" && rec.getText() != "Question and Answers"
								&& rec.getText() != "Multiple-choice Test" ){
						addonsToEdit = rec.getText();
						Ext.Ajax.request({
							url: 'addons/getAttributes.action',
							method: 'GET',
							params: {
								addonsToEdit: addonsToEdit
							},
							success: function(response, callOptions) 
							{ 
								var addon = Ext.decode(response.responseText);
								if (addon.TextWork != null){
									var textWorkform = AddonTextWorkAttributeForm.getForm();
									textWorkform.getFields().items[0].setValue(addon.TextWork.title);
									textWorkform.getFields().items[0].readOnly=true;
									if(addon.TextWork.effort == "GROUP"){
										textWorkform.getFields().items[1].setValue(false);
										textWorkform.getFields().items[2].setValue(true);
									}else{
										textWorkform.getFields().items[1].setValue(true);
										textWorkform.getFields().items[2].setValue(false);
									}
									textWorkform.getFields().items[3].setValue(addon.TextWork.minimum);
									textWorkform.getFields().items[4].setValue(addon.TextWork.maximum);
									newTextWorkWin.show();
								}
								else if (addon.UploadingFiles!=null){
									var uploadingFilesform = AddonUploadingFilesAttributeForm.getForm();
									uploadingFilesform.getFields().items[0].setValue(addon.UploadingFiles.title);
									uploadingFilesform.getFields().items[0].readOnly=true;
									if(addon.UploadingFiles.effort == "GROUP"){
										uploadingFilesform.getFields().items[1].setValue(false);
										uploadingFilesform.getFields().items[2].setValue(true);
									}else{
										uploadingFilesform.getFields().items[1].setValue(true);
										uploadingFilesform.getFields().items[2].setValue(false);
									}
									uploadingFilesform.getFields().items[3].setValue(addon.UploadingFiles.minimum);
									uploadingFilesform.getFields().items[4].setValue(addon.UploadingFiles.maximum);
									newUploadingFilesWin.show();
								}
								else if (addon.QnA!=null){
									var questionsAndAnswersform = AddonQnRAttributeForm.getForm();
									questionsAndAnswersform.getFields().items[0].setValue(addon.QnA.title);
									questionsAndAnswersform.getFields().items[0].readOnly=true;
									if(addon.QnA.effort == "GROUP"){
										questionsAndAnswersform.getFields().items[1].setValue(false);
										questionsAndAnswersform.getFields().items[2].setValue(true);
									}else{
										questionsAndAnswersform.getFields().items[1].setValue(true);
										questionsAndAnswersform.getFields().items[2].setValue(false);
									}
									questionsAndAnswersform.getFields().items[3].setValue(addon.QnA.minimum);
									questionsAndAnswersform.getFields().items[4].setValue(addon.QnA.maximum);
									newQnRWin.show();
								}
								else if (addon.MultipleChoice!=null){
									var addonMcTAttributeform = AddonMcTAttributeForm.getForm();
									addonMcTAttributeform.getFields().items[0].setValue(addon.MultipleChoice.title);
									addonMcTAttributeform.getFields().items[0].readOnly=true;
									addonMcTAttributeform.getFields().items[1].setValue(addon.MultipleChoice.numberOfQuestions);
									addonMcTAttributeform.getFields().items[2].setValue(addon.MultipleChoice.numberOfPossibleAnswers);
									newMcTWin.show();
								}
								
							}
						});
						//newRoleAttributeWin.show();
					}
				}
			},
			itemcontextmenu: {
				fn: function(view, rec, node, index, e){
					if(node.viewRecordId == "textwork" || node.viewRecordId == "uploadFiles"
						|| node.viewRecordId == "qna" || node.viewRecordId == "mct" || 
						node.viewRecordId == "Add-ons/Text work" || node.viewRecordId == "Add-ons/Uploading Files"
							|| node.viewRecordId == "Add-ons/Question and Answers" || node.viewRecordId == "Add-ons/Multiple-choice Test"){
						
						if(rec.internalId=="textwork" || rec.internalId=="Add-ons/Text work"){
							setSelectionNode(1);
						}else if(rec.internalId=="uploadFiles" || rec.internalId=="Add-ons/Uploading Files"){
							setSelectionNode(2);
						}else if(rec.internalId=="qna" || rec.internalId=="Add-ons/Question and Answers"){
							setSelectionNode(3);
						}else if(rec.internalId=="mct" || rec.internalId=="Add-ons/Multiple-choice Test"){
							setSelectionNode(4);
						}
						menuAddon.showAt(e.getXY());
					}else if(rec.internalId.indexOf("mct")===0 || rec.internalId.indexOf("Add-ons/Multiple-choice Test")===0
							|| rec.internalId.indexOf("qna")===0 || rec.internalId.indexOf("Add-ons/Question and Answers")===0){
						selectTextNode=rec.data.text;
						setSelectTextParentNode(rec.internalId);
						menuAddonDefineQuestions.showAt(e.getXY());
					}
					
				}
			} 
		}
	}); 
	
	var toolsAndMaterialsStore = Ext.create('Ext.data.TreeStore', {
		proxy: {
			type: 'ajax',
			url: 'toolsAndMaterials/getTreeToolsAndMaterials.action'
		},
		root: {
			text: 'Tools & Materials',
			id: 'root',
			expanded: true,
			children:[{
				text:'Learning Object',
				id: 'lo',
				qtip:'Right click to create a new Learning Object'
			},{
				text:'Forum Service',
				id: 'fs',
				qtip:'Right click to create a new Forum Service'
			},{
				text:'Announcement Service',
				id: 'as',
				qtip:'Right click to create a new Announcement Service'
			},{
				text:'Chat Service',
				id: 'cs',
				qtip:'Right click to create a new Chat Service'
			},{
				text:'Send Mail',
				id: 'sm',
				qtip:'Right click to create a new Send Mail'
			}
			]
		}
	});
	
	var toolsAndMaterialsTree = new  Ext.create('Ext.tree.TreePanel', {
		title: 'Tools & Materials',
		store: toolsAndMaterialsStore,
		collapsible:true,
		width:150,
		layout:'fit',
		iconCls:'green',
		viewConfig: {
		forceFit:true
		},
		titleCollapse: true,
		id: 'toolsAndMaterialsId',
		rootVisible: true,
		lines: false,
		dockedItems: [{
			xtype: 'toolbar',
			items: [ {
				text: 'Refresh',
				iconCls:'refresh',
				handler: function(){
					Ext.getCmp('toolsAndMaterialsId').getStore().load();

				}
			}]
		}],
		listeners: {
			dblclick: {
				element: 'body', //bind to the underlying body property on the panel
				fn: function(view, rec, node, index, e){ 
					if(rec.getText() != "Tools & Materials" && rec.getText() != "Learning Object" 
							&& rec.getText() != "Forum Service" && rec.getText() != "Announcement Service"
								&& rec.getText() != "Chat Service" && rec.getText() != "Send Mail" ){
						tamToEdit = rec.getText();
						setTamToEdit(tamToEdit);
						setTitle(tamToEdit);
						Ext.Ajax.request({
							url: 'tam/getAttributes.action',
							method: 'GET',
							params: {
								tamToEdit: getTitle()
							},
							success: function(response, callOptions) 
							{ 
								var tam = Ext.decode(response.responseText);
								if(tam.LearningObject != null){
									var loForm = learningObjectForm.getForm();
									loForm.getFields().items[0].setValue(tam.LearningObject.title);
									loForm.getFields().items[1].setValue(tam.LearningObject.description);
									learningObjectWin.show();
								}else if(tam.ForumService != null){
									var fsForm = forumServiceForm.getForm();
									setTitle(tam.ForumService.title);
									fsForm.getFields().items[0].setValue(tam.ForumService.title);
									fsForm.getFields().items[1].setValue(tam.ForumService.description);
									if(tam.ForumService.manager!=null){
										fsForm.getFields().items[2].setValue(tam.ForumService.manager.text);
									}
									if(tam.ForumService.moderator!=null){
										fsForm.getFields().items[3].setValue(tam.ForumService.moderator.text);
									}
									forumServiceWin.show();
									
								}else if(tam.AnnouncementService != null){
									var asForm = announcementServiceForm.getForm();
									setTitle(tam.AnnouncementService.title);
									asForm.getFields().items[0].setValue(tam.AnnouncementService.title);
									asForm.getFields().items[1].setValue(tam.AnnouncementService.description);
									if(tam.AnnouncementService.manager!=null){
										asForm.getFields().items[2].setValue(tam.AnnouncementService.manager.text);
									}
									if(tam.AnnouncementService.moderator!=null){
										asForm.getFields().items[3].setValue(tam.AnnouncementService.moderator.text);
									}
									announcementServiceWin.show();
									
								}else if(tam.ChatService != null){
									var csForm = chatServiceForm.getForm();
									setTitle(tam.ChatService.title);
									csForm.getFields().items[0].setValue(tam.ChatService.title);
									csForm.getFields().items[1].setValue(tam.ChatService.description);
									if(tam.ChatService.manager!=null){
										csForm.getFields().items[2].setValue(tam.ChatService.manager.text);
									}
									if(tam.ChatService.moderator!=null){
										csForm.getFields().items[3].setValue(tam.ChatService.moderator.text);
									}
									chatServiceWin.show();
									
								}
								else if(tam.SentMailService != null){
									var smForm = sentMailServiceForm.getForm();
									setTitle(tam.SentMailService.title);
									smForm.getFields().items[0].setValue(tam.SentMailService.title);
									smForm.getFields().items[1].setValue(tam.SentMailService.description);
									if(tam.SentMailService.manager!=null){
										smForm.getFields().items[2].setValue(tam.SentMailService.manager.text);
									}
									if(tam.SentMailService.moderator!=null){
										smForm.getFields().items[3].setValue(tam.SentMailService.moderator.text);
									}
									sentMailServiceWin.show();
									
								}
							}
						});
						
					}
				}
			},
			itemcontextmenu: {
			fn: function(view, rec, node, index, e){
				if(node.viewRecordId == "lo" || node.viewRecordId == "fs"
					|| node.viewRecordId == "as" || node.viewRecordId == "cs" || node.viewRecordId == "sm" || 
					node.viewRecordId == "Tools & Materials/Learning Object" || node.viewRecordId == "Tools & Materials/Forum Service"
						|| node.viewRecordId == "Tools & Materials/Announcement Service" || node.viewRecordId == "Tools & Materials/Chat Service" 
							|| node.viewRecordId == "Tools & Materials/Send Mail"){
					
					if(rec.internalId=="lo" || rec.internalId=="Tools & Materials/Learning Object"){
						setSelectionNode(1);
					}else if(rec.internalId=="fs" || rec.internalId=="Tools & Materials/Forum Service"){
						setSelectionNode(2);
					}else if(rec.internalId=="as" || rec.internalId=="Tools & Materials/Announcement Service"){
						setSelectionNode(3);
					}else if(rec.internalId=="cs" || rec.internalId=="Tools & Materials/Chat Service"){
						setSelectionNode(4);
					}else if(rec.internalId=="sm" || rec.internalId=="Tools & Materials/Send Mail"){
						setSelectionNode(5);
					} 
					menuToolsAndMaterials.showAt(e.getXY());
				}else if(rec.internalId.indexOf("fs")===0 || rec.internalId.indexOf("Tools & Materials/Forum Service")===0
						|| rec.internalId.indexOf("as")===0 || rec.internalId.indexOf("Tools & Materials/Announcement Service")===0
						|| rec.internalId.indexOf("cs")===0 || rec.internalId.indexOf("Tools & Materials/Chat Service")===0
						|| rec.internalId.indexOf("sm")===0 || rec.internalId.indexOf("Tools & Materials/Send Mail")===0){
					selectTextNode=rec.data.text;
					setSelectTextParentNode(rec.internalId);
					menuUsers.showAt(e.getXY());
				}
				
			}
			}
		}
	}); 
	
	
	
	
	var treeStore = Ext.create('Ext.data.TreeStore', {
		proxy: {
			type: 'ajax',
			url: 'role/getTreeRoles.action'
		},
		root: {
			text: 'Roles',
			id: 'root',
			iconCls:'roles',
			expanded: true,
			children:[{
				text:'Learner',
				id: 'learnerLeaf',
				iconCls:'learner',
				qtip:'Right click to create a new Learner Role'
			},{
				text:'Staff',
				id: 'staffLeaf',
				iconCls:'staff',
				qtip:'Right click to create a new Staff Role'
			}
			]
		}
	});
	
	
	var rolesTree = new  Ext.create('Ext.tree.TreePanel', {
		title: 'Roles',
		store: treeStore,
		contentEl: 'west1',
		title: 'Roles',
		autoScroll: true,
		autoHeight:true,
		autoWidth:true,
		collapsible:true,
		titleCollapse: true,
		id: 'rolesTreeId',
		iconCls:'orange',
		rootVisible: true,
		width:150,
		layout:'fit',
		viewConfig: {
		forceFit:true
		},
		lines: false,
		viewConfig: {
			plugins: {
				ptype: 'treeviewdragdrop',
				appendOnly: true
			}
		},
		dockedItems: [{
			xtype: 'toolbar',
			iconCls:'icon-user-add',
			items: [{
				text: 'Refresh',
				iconCls:'refresh',
				handler: function(){
					Ext.getCmp('rolesTreeId').getStore().load();

				}
			}]
		}],
		listeners: {
			dblclick: {
				element: 'body', //bind to the underlying body property on the panel
				fn: function(view, rec, node, index, e){ 
					if(rec.getText() != "Learner" && rec.getText() != "Staff" && rec.getText() != "Roles" ){
						roleToEdit = rec.getText();
						Ext.Ajax.request({
							url: 'role/getAttributes.action',
							method: 'GET',
							params: {
								roleToEdit: roleToEdit
							},
							success: function(response, callOptions) 
							{ 
								var role = Ext.decode(response.responseText).role;
								var formRole = RoleAttributeForm.getForm();
								formRole.getFields().items[0].setValue(role.text);
								if(role.allowCreation == true){
									formRole.getFields().items[1].setValue(true);
									formRole.getFields().items[2].setValue(false);
								}else{
									formRole.getFields().items[1].setValue(false);
									formRole.getFields().items[2].setValue(true);
								}
								if(role.notAssignToOther == true){
									formRole.getFields().items[3].setValue(true);
									formRole.getFields().items[4].setValue(false);
								}else{
									formRole.getFields().items[3].setValue(false);
									formRole.getFields().items[4].setValue(true);
								}
								formRole.getFields().items[5].setValue(role.minPersons);
								formRole.getFields().items[6].setValue(role.maxPersons);
								if(role.information != null){
									formRole.getFields().items[7].setValue(role.information);
								}
							}
						});
						newRoleAttributeWin.show();
					}
				}
			},
			render: {
				fn: function() {
					// After the component has been rendered, disable the default browser context menu
					Ext.getBody().on("contextmenu", Ext.emptyFn, null, {preventDefault: true});
				}
			},
			itemcontextmenu: {
				fn: function(view, rec, node, index, e){
					if(node.viewRecordId == "learnerLeaf" || node.viewRecordId == "staffLeaf"
						|| node.viewRecordId == "Roles/Learner" || node.viewRecordId == "Roles/Staff"){
						selectedNode = index;
						menuC.showAt(e.getXY());
					}
				}
			}            	                       
		}
	}); 

	var eastTabPanel = Ext.create('Ext.tab.Panel', {
		region: 'west', // a center region is ALWAYS required for border layout
		id : 'west-panel',
		tabPosition: 'top',
		//deferredRender: false,
		split: true,
    	width: 200,
    	//height: 500,
    	collapsible: true,
    	animCollapse: true,
		items: [rolesTree,toolsAndMaterialsTree]//addonsTree,
	});
	
		
    Ext.define("Post", {
        extend: 'Ext.data.Model',
		proxy: {
			type: 'ajax',
			url: 'uol/viewAutocomplete.action',  // url that will load data with respect to User and limit params
			reader: {
				type: 'json',
				root: 'items',
				totalProperty: 'total'
			}
		},

        fields:['id','title','description']
    });

    var ds = Ext.create('Ext.data.Store', {
        pageSize: 10,
        model: 'Post'
    });
    

var validated = false;
	
	var toolBar = Ext.create('Ext.toolbar.Toolbar', {
		region: 'north',
		//html: '<img alt="csdcdc" src="title.png"/>',

		height: 82, // give north and south regions a height
		items: [
		        {
		        	xtype: 'splitbutton',
		        	text : 'File',
		        	iconCls: 'ld',
		        	menu: [{
		        		text: 'New',
		        		id: 'FilenewItem',
		        		iconCls:'new',
		        		handler: function(){
		        			newUoLWin.show();
		        			renderTo: Ext.getBody();
		        		}
		        	},{
		        		text: 'Open',
		        		id: 'FileopenItem',
		        		iconCls:'openFile',
		        		handler: function(){
		        			openWinUoL.show();
		        			renderTo: Ext.getBody();
		        		}
		        	},{
		        		text: 'Save',
		        		id :'FilesaveItem',
		        		iconCls:'save',
		        		handler: function(){
		        			
		        			Ext.Ajax.request({
		        				url: 'graph/saveGraph.action',
		        				success: function(response,options) 
		        				{ 
//		        					activityId="Support:"+this.id;
//		        					supportActivityWin.show();
		        				},
		        				params: { htmlCode: new XMLSerializer_01().toXML(workflow)},
//		        					activityId:"Support:"+this.id},
		        				failure: function(response,options) 
		        				{ 
		        				}
		        			});
		        			
		        		}
		        	}]
		        },
		        '-',
		        {
		        	xtype: 'splitbutton',
		        	text : 'Learning Design',
		        	iconCls: 'tools',
		        	menu: [{
		        		text: 'Import Learning Design',
		        		id: 'Import Learning Design',
		        		iconCls:'new',
		        		handler: function(){
		        			importLDWin.show();
		        		}
		        	},{
		        		text: 'Validate & Export Learning Design',
		        		id: 'Export as Learning Design',
		        		iconCls:'openFile',
		        		menu: {        // <-- submenu by nested config object
		                    items: [
		                        {
		                            text: 'Validate',
		                            id: 'Validate',
		                            	handler: function(){
		                            		Ext.Ajax.request({
		        		        				url: 'learningDesign/validate.action',
		        		        				success: function(response,options) 
		        		        				{ 
		        		        					var result = Ext.decode(response.responseText);
		        		        					if(result.failure){
		        		        						validated = false;
		        		        						Ext.Msg.alert('Error', result.data);
		        		        					}else{
		        		        						validated = true;
		        		        						Ext.getCmp("Export").enable(true);
		        		        						Ext.Msg.alert('Success', 'Learning Design validated successfully');
		        		        						
		        		        					}
		        		        				},
		        		        				params: { htmlCode: new XMLSerializer_01().toXML(workflow)},

		        		        				failure: function(response,options) 
		        		        				{ 
		        		        					console.log("failure");
		        		        				}
		        		        			});
		                            		
			                            }
		                        }, {
		                            text: 'Export',
		                            id: 'Export',
		                            disabled:true,
		                            handler: function(){
		    		        			 window.open('learningDesign/export.action');
		                            }
		                        }
		                    ]
		                }
		        	}]
		        },
		            '->',{
		        	id:'boxImage',
		        	xtype: 'tbfill',
					autoEl:'<img alt="csdcdc" src="title.png" height="80px;" />',
					style : {textAlign : 'center' },
					layoutConfig: {
					    pack:'center',
					    align:'middle'
					  }
				},
		        '->',
		        {
		            xtype: 'combo',
		            store: ds,
		            displayField: 'title',
		            typeAhead: false,
		            hideLabel: false,
		            hideTrigger:true,
		            width:400,
		            id:'autocompleteUoL',
		            anchor: '100%',
		            fieldLabel: 'Search LD\'s',
		            params: { htmlCode: new XMLSerializer_01().toXML(workflow) },
		            listConfig: {
		                loadingText: 'Searching...',
		                emptyText: 'No matching posts found.'
		                	//,

		                // Custom rendering template for each item

		            },
		            pageSize: 10,
		            // override default onSelect to do redirect
		            listeners: {
		                select: function(combo, selection) {
		                    var post = selection[0];
		                   var id = post.data.id;
		                    if (id!=null) {
		                		Ext.Ajax.request({
		                			url: 'configure/session.action',
		                			params: {
		                				id: id
		                			},
		                			success: function(response,options) 
		                			{ 
		                				workflow.clear();
		                				var tab  = tabPanel.getActiveTab();
		                				var responseText = response.responseText;
		                				var array=responseText.split(",");
		                				var addon = Ext.decode(response.responseText);
		                				var parser=new DOMParser();
		                				var doc=parser.parseFromString(addon.graph,"text/xml");
		                				var pp = doc.documentElement.children;
		                				new deserializer_01.prototype.fromXML(pp, workflow);      
		                				var array2=array[3].split(":");
		                				tab.setTitle(array2[1]);
		                				var west = Ext.getCmp('west-panel');
	        							west.getEl().unmask();
	        							var east = Ext.getCmp('east-panel');
	        							east.getEl().unmask();
	        							var center = Ext.getCmp('center-panel');
	        							center.getEl().unmask();
		                				Ext.getCmp('rolesTreeId').getStore().load();
		                				Ext.getCmp('addonsId').getStore().load();
		                				Ext.getCmp('autocompleteUoL').clearValue();
		                			}
		                		});
//		                        window.location =
//		                            Ext.String.format('http://www.sencha.com/forum/showthread.php?t={0}&p={1}', post.get('topicId'), post.get('id'));
		                    }
		                }
		            }
		        }
		        ]
	});
	
    function onItemClick(item){
        Ext.example.msg('Menu Click', 'You clicked the "{0}" menu item.', item.text);
    }
    


	viewport = Ext.create('Ext.Viewport', {
		id: 'border-example',
		layout: 'border',
		items: [{
	        xtype: 'box',
	        region: 'north',
	        applyTo: 'HeaderCap',
	        height: 30
	    },
		        // create instance immediately
		        toolBar
		        , {
		        	region: 'east',
		        	id:'east-panel',
		        	title: 'East',
		        	split: false,
		        	width: 200,
		        	height: 500,
		        	collapsible: true,
		        	animCollapse: true,
		        	layout:'accordion',
		        	items:[{
		        		title: 'Points',
		        		iconCls:'points',
		        		contentEl: 'points'
		        	},{
		        		title: 'Model',
		        		iconCls:'model',
		        		contentEl: 'west2'
		        	}]
		        }, eastTabPanel,
		        tabPanel
		        ]
	});
	Ext.get("hideit").on('click', function(){
		var w = Ext.getCmp('west-panel');
		w.collapsed ? w.expand() : w.collapse();
	});
	var dragsource1=new Ext.dd.DragSource("activity", {ddGroup:'TreeDD',dragData:{name: Activity.prototype.type}}); 
	var dragsource2=new Ext.dd.DragSource("supportactivity", {ddGroup:'TreeDD',dragData:{name: SupportActivity.prototype.type}}); 
	var dragsource3=new Ext.dd.DragSource("start", {ddGroup:'TreeDD',dragData:{name: Start.prototype.type}}); 
	var dragsource4=new Ext.dd.DragSource("exit", {ddGroup:'TreeDD',dragData:{name: Exit.prototype.type}}); 
	var dragsource5=new Ext.dd.DragSource("OneToTwo", {ddGroup:'TreeDD',dragData:{name: OneToTwo.prototype.type}}); 
	var dragsource5=new Ext.dd.DragSource("TwoToOne", {ddGroup:'TreeDD',dragData:{name: TwoToOne.prototype.type}}); 
	var droptarget=new Ext.dd.DropTarget("center1",{ddGroup:'TreeDD'});

	droptarget.notifyDrop=function(dd, e, data)
	{
		var figuresSize = workflow.getFigures().size;
		if(data.name)
		{
			var xOffset    = workflow.getAbsoluteX();
			var yOffset    = workflow.getAbsoluteY();
			var scrollLeft = workflow.getScrollLeft();
			var scrollTop  = workflow.getScrollTop();

			figure = new Figure();

			workflow.addFigure(eval("new "+data.name+"()"),e.xy[0]-xOffset+scrollLeft,e.xy[1]-yOffset+scrollTop);
			return true;
		}
	}

	workflow.onMouseDown = function(x, y){

		var ob = workflow.getCurrentSelection();
		g.setSource({
			"Name": ob.type,
			"Min Number of Persons": 0,
			"Max Number of Persons": 0,
			"productionQuality": false,
			"created": Ext.Date.parse('10/15/2006', 'd/m/Y'),
			"tested": false,
			"version": 0.01,
			"borderWidth": 1,
			"boss": true,
			"ActorId": ob.getId()
		});
	}
	

//SupportActivity.prototype.onRemove=function(){
//	Ext.Ajax.request({
//		url: 'graph/removedSA.action',
//		success: function(response,options) 
//		{ 
//			activityId="SupportActivity:"+this.id;
//			Ext.getCmp("Export").disable(true);
//		},
//		params: { htmlCode: new XMLSerializer_01().toXML(workflow),
//			activityId:"SupportActivity:"+this.id},
//		failure: function(response,options) 
//		{ 
//		}
//	});
//}
//
//Activity.prototype.onRemove=function(){
//	alert("Removed LA"+this.id);
//}


});

//eof
